@@ -1,790 +1,791 | |||||
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 | # SUBCHANNELS EN VEZ DE CHANNELS |
|
7 | # SUBCHANNELS EN VEZ DE CHANNELS | |
8 | # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO |
|
8 | # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO | |
9 | # ACTUALIZACION DE VERSION |
|
9 | # ACTUALIZACION DE VERSION | |
10 | # HEADERS |
|
10 | # HEADERS | |
11 | # MODULO DE ESCRITURA |
|
11 | # MODULO DE ESCRITURA | |
12 | # METADATA |
|
12 | # METADATA | |
13 |
|
13 | |||
14 | import os |
|
14 | import os | |
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 |
|
19 | |||
20 | try: |
|
20 | try: | |
21 | from gevent import sleep |
|
21 | from gevent import sleep | |
22 | except: |
|
22 | except: | |
23 | from time import sleep |
|
23 | from time import sleep | |
24 |
|
24 | |||
25 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader |
|
25 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
26 | from schainpy.model.data.jrodata import Voltage |
|
26 | from schainpy.model.data.jrodata import Voltage | |
27 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
27 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
28 | from time import time |
|
28 | from time import time | |
29 |
|
29 | |||
30 | import cPickle |
|
30 | import cPickle | |
31 | try: |
|
31 | try: | |
32 | import digital_rf |
|
32 | import digital_rf | |
33 | except: |
|
33 | except: | |
34 | print 'You should install "digital_rf" module if you want to read Digital RF data' |
|
34 | print 'You should install "digital_rf" module if you want to read Digital RF data' | |
35 |
|
35 | |||
36 |
|
36 | |||
37 | class DigitalRFReader(ProcessingUnit): |
|
37 | class DigitalRFReader(ProcessingUnit): | |
38 | ''' |
|
38 | ''' | |
39 | classdocs |
|
39 | classdocs | |
40 | ''' |
|
40 | ''' | |
41 |
|
41 | |||
42 | def __init__(self, **kwargs): |
|
42 | def __init__(self, **kwargs): | |
43 | ''' |
|
43 | ''' | |
44 | Constructor |
|
44 | Constructor | |
45 | ''' |
|
45 | ''' | |
46 |
|
46 | |||
47 | ProcessingUnit.__init__(self, **kwargs) |
|
47 | ProcessingUnit.__init__(self, **kwargs) | |
48 |
|
48 | |||
49 | self.dataOut = Voltage() |
|
49 | self.dataOut = Voltage() | |
50 | self.__printInfo = True |
|
50 | self.__printInfo = True | |
51 | self.__flagDiscontinuousBlock = False |
|
51 | self.__flagDiscontinuousBlock = False | |
52 | self.__bufferIndex = 9999999 |
|
52 | self.__bufferIndex = 9999999 | |
53 | self.__ippKm = None |
|
53 | self.__ippKm = None | |
54 | self.__codeType = 0 |
|
54 | self.__codeType = 0 | |
55 | self.__nCode = None |
|
55 | self.__nCode = None | |
56 | self.__nBaud = None |
|
56 | self.__nBaud = None | |
57 | self.__code = None |
|
57 | self.__code = None | |
58 | self.dtype = None |
|
58 | self.dtype = None | |
|
59 | self.oldAverage = None | |||
59 |
|
60 | |||
60 | def close(self): |
|
61 | def close(self): | |
61 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 |
|
62 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 | |
62 | return |
|
63 | return | |
63 |
|
64 | |||
64 | def __getCurrentSecond(self): |
|
65 | def __getCurrentSecond(self): | |
65 |
|
66 | |||
66 | return self.__thisUnixSample / self.__sample_rate |
|
67 | return self.__thisUnixSample / self.__sample_rate | |
67 |
|
68 | |||
68 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") |
|
69 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") | |
69 |
|
70 | |||
70 | def __setFileHeader(self): |
|
71 | def __setFileHeader(self): | |
71 | ''' |
|
72 | ''' | |
72 | In this method will be initialized every parameter of dataOut object (header, no data) |
|
73 | In this method will be initialized every parameter of dataOut object (header, no data) | |
73 | ''' |
|
74 | ''' | |
74 | ippSeconds = 1.0 * self.__nSamples / self.__sample_rate |
|
75 | ippSeconds = 1.0 * self.__nSamples / self.__sample_rate | |
75 |
|
76 | |||
76 | nProfiles = 1.0 / ippSeconds # Number of profiles in one second |
|
77 | nProfiles = 1.0 / ippSeconds # Number of profiles in one second | |
77 |
|
78 | |||
78 | try: |
|
79 | try: | |
79 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( |
|
80 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( | |
80 | self.__radarControllerHeader) |
|
81 | self.__radarControllerHeader) | |
81 | except: |
|
82 | except: | |
82 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( |
|
83 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( | |
83 | txA=0, |
|
84 | txA=0, | |
84 | txB=0, |
|
85 | txB=0, | |
85 | nWindows=1, |
|
86 | nWindows=1, | |
86 | nHeights=self.__nSamples, |
|
87 | nHeights=self.__nSamples, | |
87 | firstHeight=self.__firstHeigth, |
|
88 | firstHeight=self.__firstHeigth, | |
88 | deltaHeight=self.__deltaHeigth, |
|
89 | deltaHeight=self.__deltaHeigth, | |
89 | codeType=self.__codeType, |
|
90 | codeType=self.__codeType, | |
90 | nCode=self.__nCode, nBaud=self.__nBaud, |
|
91 | nCode=self.__nCode, nBaud=self.__nBaud, | |
91 | code=self.__code) |
|
92 | code=self.__code) | |
92 |
|
93 | |||
93 | try: |
|
94 | try: | |
94 | self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader) |
|
95 | self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader) | |
95 | except: |
|
96 | except: | |
96 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, |
|
97 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, | |
97 | nProfiles=nProfiles, |
|
98 | nProfiles=nProfiles, | |
98 | nChannels=len( |
|
99 | nChannels=len( | |
99 | self.__channelList), |
|
100 | self.__channelList), | |
100 | adcResolution=14) |
|
101 | adcResolution=14) | |
101 | self.dataOut.type = "Voltage" |
|
102 | self.dataOut.type = "Voltage" | |
102 |
|
103 | |||
103 | self.dataOut.data = None |
|
104 | self.dataOut.data = None | |
104 |
|
105 | |||
105 | self.dataOut.dtype = self.dtype |
|
106 | self.dataOut.dtype = self.dtype | |
106 |
|
107 | |||
107 | # self.dataOut.nChannels = 0 |
|
108 | # self.dataOut.nChannels = 0 | |
108 |
|
109 | |||
109 | # self.dataOut.nHeights = 0 |
|
110 | # self.dataOut.nHeights = 0 | |
110 |
|
111 | |||
111 | self.dataOut.nProfiles = int(nProfiles) |
|
112 | self.dataOut.nProfiles = int(nProfiles) | |
112 |
|
113 | |||
113 | self.dataOut.heightList = self.__firstHeigth + \ |
|
114 | self.dataOut.heightList = self.__firstHeigth + \ | |
114 | numpy.arange(self.__nSamples, dtype=numpy.float) * \ |
|
115 | numpy.arange(self.__nSamples, dtype=numpy.float) * \ | |
115 | self.__deltaHeigth |
|
116 | self.__deltaHeigth | |
116 |
|
117 | |||
117 | self.dataOut.channelList = range(self.__num_subchannels) |
|
118 | self.dataOut.channelList = range(self.__num_subchannels) | |
118 |
|
119 | |||
119 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() |
|
120 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() | |
120 |
|
121 | |||
121 | # self.dataOut.channelIndexList = None |
|
122 | # self.dataOut.channelIndexList = None | |
122 |
|
123 | |||
123 | self.dataOut.flagNoData = True |
|
124 | self.dataOut.flagNoData = True | |
124 |
|
125 | |||
125 | self.dataOut.flagDataAsBlock = False |
|
126 | self.dataOut.flagDataAsBlock = False | |
126 | # Set to TRUE if the data is discontinuous |
|
127 | # Set to TRUE if the data is discontinuous | |
127 | self.dataOut.flagDiscontinuousBlock = False |
|
128 | self.dataOut.flagDiscontinuousBlock = False | |
128 |
|
129 | |||
129 | self.dataOut.utctime = None |
|
130 | self.dataOut.utctime = None | |
130 |
|
131 | |||
131 | # timezone like jroheader, difference in minutes between UTC and localtime |
|
132 | # timezone like jroheader, difference in minutes between UTC and localtime | |
132 | self.dataOut.timeZone = self.__timezone / 60 |
|
133 | self.dataOut.timeZone = self.__timezone / 60 | |
133 |
|
134 | |||
134 | self.dataOut.dstFlag = 0 |
|
135 | self.dataOut.dstFlag = 0 | |
135 |
|
136 | |||
136 | self.dataOut.errorCount = 0 |
|
137 | self.dataOut.errorCount = 0 | |
137 |
|
138 | |||
138 | try: |
|
139 | try: | |
139 | self.dataOut.nCohInt = self.fixed_metadata_dict.get( |
|
140 | self.dataOut.nCohInt = self.fixed_metadata_dict.get( | |
140 | 'nCohInt', self.nCohInt) |
|
141 | 'nCohInt', self.nCohInt) | |
141 |
|
142 | |||
142 | # asumo que la data esta decodificada |
|
143 | # asumo que la data esta decodificada | |
143 | self.dataOut.flagDecodeData = self.fixed_metadata_dict.get( |
|
144 | self.dataOut.flagDecodeData = self.fixed_metadata_dict.get( | |
144 | 'flagDecodeData', self.flagDecodeData) |
|
145 | 'flagDecodeData', self.flagDecodeData) | |
145 |
|
146 | |||
146 | # asumo que la data esta sin flip |
|
147 | # asumo que la data esta sin flip | |
147 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] |
|
148 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] | |
148 |
|
149 | |||
149 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] |
|
150 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] | |
150 |
|
151 | |||
151 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] |
|
152 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] | |
152 | except: |
|
153 | except: | |
153 | pass |
|
154 | pass | |
154 |
|
155 | |||
155 | self.dataOut.ippSeconds = ippSeconds |
|
156 | self.dataOut.ippSeconds = ippSeconds | |
156 |
|
157 | |||
157 | # Time interval between profiles |
|
158 | # Time interval between profiles | |
158 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
159 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
159 |
|
160 | |||
160 | self.dataOut.frequency = self.__frequency |
|
161 | self.dataOut.frequency = self.__frequency | |
161 |
|
162 | |||
162 | self.dataOut.realtime = self.__online |
|
163 | self.dataOut.realtime = self.__online | |
163 |
|
164 | |||
164 | def findDatafiles(self, path, startDate=None, endDate=None): |
|
165 | def findDatafiles(self, path, startDate=None, endDate=None): | |
165 |
|
166 | |||
166 | if not os.path.isdir(path): |
|
167 | if not os.path.isdir(path): | |
167 | return [] |
|
168 | return [] | |
168 |
|
169 | |||
169 | try: |
|
170 | try: | |
170 | digitalReadObj = digital_rf.DigitalRFReader( |
|
171 | digitalReadObj = digital_rf.DigitalRFReader( | |
171 | path, load_all_metadata=True) |
|
172 | path, load_all_metadata=True) | |
172 | except: |
|
173 | except: | |
173 | digitalReadObj = digital_rf.DigitalRFReader(path) |
|
174 | digitalReadObj = digital_rf.DigitalRFReader(path) | |
174 |
|
175 | |||
175 | channelNameList = digitalReadObj.get_channels() |
|
176 | channelNameList = digitalReadObj.get_channels() | |
176 |
|
177 | |||
177 | if not channelNameList: |
|
178 | if not channelNameList: | |
178 | return [] |
|
179 | return [] | |
179 |
|
180 | |||
180 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) |
|
181 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) | |
181 |
|
182 | |||
182 | sample_rate = metadata_dict['sample_rate'][0] |
|
183 | sample_rate = metadata_dict['sample_rate'][0] | |
183 |
|
184 | |||
184 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) |
|
185 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) | |
185 |
|
186 | |||
186 | try: |
|
187 | try: | |
187 | timezone = this_metadata_file['timezone'].value |
|
188 | timezone = this_metadata_file['timezone'].value | |
188 | except: |
|
189 | except: | |
189 | timezone = 0 |
|
190 | timezone = 0 | |
190 |
|
191 | |||
191 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( |
|
192 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( | |
192 | channelNameList[0]) / sample_rate - timezone |
|
193 | channelNameList[0]) / sample_rate - timezone | |
193 |
|
194 | |||
194 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) |
|
195 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) | |
195 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) |
|
196 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) | |
196 |
|
197 | |||
197 | if not startDate: |
|
198 | if not startDate: | |
198 | startDate = startDatetime.date() |
|
199 | startDate = startDatetime.date() | |
199 |
|
200 | |||
200 | if not endDate: |
|
201 | if not endDate: | |
201 | endDate = endDatatime.date() |
|
202 | endDate = endDatatime.date() | |
202 |
|
203 | |||
203 | dateList = [] |
|
204 | dateList = [] | |
204 |
|
205 | |||
205 | thisDatetime = startDatetime |
|
206 | thisDatetime = startDatetime | |
206 |
|
207 | |||
207 | while(thisDatetime <= endDatatime): |
|
208 | while(thisDatetime <= endDatatime): | |
208 |
|
209 | |||
209 | thisDate = thisDatetime.date() |
|
210 | thisDate = thisDatetime.date() | |
210 |
|
211 | |||
211 | if thisDate < startDate: |
|
212 | if thisDate < startDate: | |
212 | continue |
|
213 | continue | |
213 |
|
214 | |||
214 | if thisDate > endDate: |
|
215 | if thisDate > endDate: | |
215 | break |
|
216 | break | |
216 |
|
217 | |||
217 | dateList.append(thisDate) |
|
218 | dateList.append(thisDate) | |
218 | thisDatetime += datetime.timedelta(1) |
|
219 | thisDatetime += datetime.timedelta(1) | |
219 |
|
220 | |||
220 | return dateList |
|
221 | return dateList | |
221 |
|
222 | |||
222 | def setup(self, path=None, |
|
223 | def setup(self, path=None, | |
223 | startDate=None, |
|
224 | startDate=None, | |
224 | endDate=None, |
|
225 | endDate=None, | |
225 | startTime=datetime.time(0, 0, 0), |
|
226 | startTime=datetime.time(0, 0, 0), | |
226 | endTime=datetime.time(23, 59, 59), |
|
227 | endTime=datetime.time(23, 59, 59), | |
227 | channelList=None, |
|
228 | channelList=None, | |
228 | nSamples=None, |
|
229 | nSamples=None, | |
229 | online=False, |
|
230 | online=False, | |
230 | delay=60, |
|
231 | delay=60, | |
231 | buffer_size=1024, |
|
232 | buffer_size=1024, | |
232 | ippKm=None, |
|
233 | ippKm=None, | |
233 | nCohInt=1, |
|
234 | nCohInt=1, | |
234 | nCode=1, |
|
235 | nCode=1, | |
235 | nBaud=1, |
|
236 | nBaud=1, | |
236 | flagDecodeData=False, |
|
237 | flagDecodeData=False, | |
237 | code=numpy.ones((1, 1), dtype=numpy.int), |
|
238 | code=numpy.ones((1, 1), dtype=numpy.int), | |
238 | **kwargs): |
|
239 | **kwargs): | |
239 | ''' |
|
240 | ''' | |
240 | In this method we should set all initial parameters. |
|
241 | In this method we should set all initial parameters. | |
241 |
|
242 | |||
242 | Inputs: |
|
243 | Inputs: | |
243 | path |
|
244 | path | |
244 | startDate |
|
245 | startDate | |
245 | endDate |
|
246 | endDate | |
246 | startTime |
|
247 | startTime | |
247 | endTime |
|
248 | endTime | |
248 | set |
|
249 | set | |
249 | expLabel |
|
250 | expLabel | |
250 | ext |
|
251 | ext | |
251 | online |
|
252 | online | |
252 | delay |
|
253 | delay | |
253 | ''' |
|
254 | ''' | |
254 | self.nCohInt = nCohInt |
|
255 | self.nCohInt = nCohInt | |
255 | self.flagDecodeData = flagDecodeData |
|
256 | self.flagDecodeData = flagDecodeData | |
256 | self.i = 0 |
|
257 | self.i = 0 | |
257 | if not os.path.isdir(path): |
|
258 | if not os.path.isdir(path): | |
258 | raise ValueError, "[Reading] Directory %s does not exist" % path |
|
259 | raise ValueError, "[Reading] Directory %s does not exist" % path | |
259 |
|
260 | |||
260 | try: |
|
261 | try: | |
261 | self.digitalReadObj = digital_rf.DigitalRFReader( |
|
262 | self.digitalReadObj = digital_rf.DigitalRFReader( | |
262 | path, load_all_metadata=True) |
|
263 | path, load_all_metadata=True) | |
263 | except: |
|
264 | except: | |
264 | self.digitalReadObj = digital_rf.DigitalRFReader(path) |
|
265 | self.digitalReadObj = digital_rf.DigitalRFReader(path) | |
265 |
|
266 | |||
266 | channelNameList = self.digitalReadObj.get_channels() |
|
267 | channelNameList = self.digitalReadObj.get_channels() | |
267 |
|
268 | |||
268 | if not channelNameList: |
|
269 | if not channelNameList: | |
269 | raise ValueError, "[Reading] Directory %s does not have any files" % path |
|
270 | raise ValueError, "[Reading] Directory %s does not have any files" % path | |
270 |
|
271 | |||
271 | if not channelList: |
|
272 | if not channelList: | |
272 | channelList = range(len(channelNameList)) |
|
273 | channelList = range(len(channelNameList)) | |
273 |
|
274 | |||
274 | ########## Reading metadata ###################### |
|
275 | ########## Reading metadata ###################### | |
275 |
|
276 | |||
276 | top_properties = self.digitalReadObj.get_properties( |
|
277 | top_properties = self.digitalReadObj.get_properties( | |
277 | channelNameList[channelList[0]]) |
|
278 | channelNameList[channelList[0]]) | |
278 |
|
279 | |||
279 | self.__num_subchannels = top_properties['num_subchannels'] |
|
280 | self.__num_subchannels = top_properties['num_subchannels'] | |
280 | self.__sample_rate = 1.0 * \ |
|
281 | self.__sample_rate = 1.0 * \ | |
281 | top_properties['sample_rate_numerator'] / \ |
|
282 | top_properties['sample_rate_numerator'] / \ | |
282 | top_properties['sample_rate_denominator'] |
|
283 | top_properties['sample_rate_denominator'] | |
283 | # self.__samples_per_file = top_properties['samples_per_file'][0] |
|
284 | # self.__samples_per_file = top_properties['samples_per_file'][0] | |
284 | self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15? |
|
285 | self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15? | |
285 |
|
286 | |||
286 | this_metadata_file = self.digitalReadObj.get_digital_metadata( |
|
287 | this_metadata_file = self.digitalReadObj.get_digital_metadata( | |
287 | channelNameList[channelList[0]]) |
|
288 | channelNameList[channelList[0]]) | |
288 | metadata_bounds = this_metadata_file.get_bounds() |
|
289 | metadata_bounds = this_metadata_file.get_bounds() | |
289 | self.fixed_metadata_dict = this_metadata_file.read( |
|
290 | self.fixed_metadata_dict = this_metadata_file.read( | |
290 | metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER |
|
291 | metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER | |
291 |
|
292 | |||
292 | try: |
|
293 | try: | |
293 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] |
|
294 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] | |
294 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] |
|
295 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] | |
295 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] |
|
296 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] | |
296 | self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype']) |
|
297 | self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype']) | |
297 | except: |
|
298 | except: | |
298 | pass |
|
299 | pass | |
299 |
|
300 | |||
300 | self.__frequency = None |
|
301 | self.__frequency = None | |
301 |
|
302 | |||
302 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) |
|
303 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) | |
303 |
|
304 | |||
304 | self.__timezone = self.fixed_metadata_dict.get('timezone', 300) |
|
305 | self.__timezone = self.fixed_metadata_dict.get('timezone', 300) | |
305 |
|
306 | |||
306 | try: |
|
307 | try: | |
307 | nSamples = self.fixed_metadata_dict['nSamples'] |
|
308 | nSamples = self.fixed_metadata_dict['nSamples'] | |
308 | except: |
|
309 | except: | |
309 | nSamples = None |
|
310 | nSamples = None | |
310 |
|
311 | |||
311 | self.__firstHeigth = 0 |
|
312 | self.__firstHeigth = 0 | |
312 |
|
313 | |||
313 | try: |
|
314 | try: | |
314 | codeType = self.__radarControllerHeader['codeType'] |
|
315 | codeType = self.__radarControllerHeader['codeType'] | |
315 | except: |
|
316 | except: | |
316 | codeType = 0 |
|
317 | codeType = 0 | |
317 |
|
318 | |||
318 | try: |
|
319 | try: | |
319 | if codeType: |
|
320 | if codeType: | |
320 | nCode = self.__radarControllerHeader['nCode'] |
|
321 | nCode = self.__radarControllerHeader['nCode'] | |
321 | nBaud = self.__radarControllerHeader['nBaud'] |
|
322 | nBaud = self.__radarControllerHeader['nBaud'] | |
322 | code = self.__radarControllerHeader['code'] |
|
323 | code = self.__radarControllerHeader['code'] | |
323 | except: |
|
324 | except: | |
324 | pass |
|
325 | pass | |
325 |
|
326 | |||
326 | if not ippKm: |
|
327 | if not ippKm: | |
327 | try: |
|
328 | try: | |
328 | # seconds to km |
|
329 | # seconds to km | |
329 | ippKm = self.__radarControllerHeader['ipp'] |
|
330 | ippKm = self.__radarControllerHeader['ipp'] | |
330 | except: |
|
331 | except: | |
331 | ippKm = None |
|
332 | ippKm = None | |
332 | #################################################### |
|
333 | #################################################### | |
333 | self.__ippKm = ippKm |
|
334 | self.__ippKm = ippKm | |
334 | startUTCSecond = None |
|
335 | startUTCSecond = None | |
335 | endUTCSecond = None |
|
336 | endUTCSecond = None | |
336 |
|
337 | |||
337 | if startDate: |
|
338 | if startDate: | |
338 | startDatetime = datetime.datetime.combine(startDate, startTime) |
|
339 | startDatetime = datetime.datetime.combine(startDate, startTime) | |
339 | startUTCSecond = ( |
|
340 | startUTCSecond = ( | |
340 | startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone |
|
341 | startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone | |
341 |
|
342 | |||
342 | if endDate: |
|
343 | if endDate: | |
343 | endDatetime = datetime.datetime.combine(endDate, endTime) |
|
344 | endDatetime = datetime.datetime.combine(endDate, endTime) | |
344 | endUTCSecond = (endDatetime - datetime.datetime(1970, |
|
345 | endUTCSecond = (endDatetime - datetime.datetime(1970, | |
345 | 1, 1)).total_seconds() + self.__timezone |
|
346 | 1, 1)).total_seconds() + self.__timezone | |
346 |
|
347 | |||
347 | start_index, end_index = self.digitalReadObj.get_bounds( |
|
348 | start_index, end_index = self.digitalReadObj.get_bounds( | |
348 | channelNameList[channelList[0]]) |
|
349 | channelNameList[channelList[0]]) | |
349 |
|
350 | |||
350 | if not startUTCSecond: |
|
351 | if not startUTCSecond: | |
351 | startUTCSecond = start_index / self.__sample_rate |
|
352 | startUTCSecond = start_index / self.__sample_rate | |
352 |
|
353 | |||
353 | if start_index > startUTCSecond * self.__sample_rate: |
|
354 | if start_index > startUTCSecond * self.__sample_rate: | |
354 | startUTCSecond = start_index / self.__sample_rate |
|
355 | startUTCSecond = start_index / self.__sample_rate | |
355 |
|
356 | |||
356 | if not endUTCSecond: |
|
357 | if not endUTCSecond: | |
357 | endUTCSecond = end_index / self.__sample_rate |
|
358 | endUTCSecond = end_index / self.__sample_rate | |
358 |
|
359 | |||
359 | if end_index < endUTCSecond * self.__sample_rate: |
|
360 | if end_index < endUTCSecond * self.__sample_rate: | |
360 | endUTCSecond = end_index / self.__sample_rate |
|
361 | endUTCSecond = end_index / self.__sample_rate | |
361 | if not nSamples: |
|
362 | if not nSamples: | |
362 | if not ippKm: |
|
363 | if not ippKm: | |
363 | raise ValueError, "[Reading] nSamples or ippKm should be defined" |
|
364 | raise ValueError, "[Reading] nSamples or ippKm should be defined" | |
364 | nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate)) |
|
365 | nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate)) | |
365 | channelBoundList = [] |
|
366 | channelBoundList = [] | |
366 | channelNameListFiltered = [] |
|
367 | channelNameListFiltered = [] | |
367 |
|
368 | |||
368 | for thisIndexChannel in channelList: |
|
369 | for thisIndexChannel in channelList: | |
369 | thisChannelName = channelNameList[thisIndexChannel] |
|
370 | thisChannelName = channelNameList[thisIndexChannel] | |
370 | start_index, end_index = self.digitalReadObj.get_bounds( |
|
371 | start_index, end_index = self.digitalReadObj.get_bounds( | |
371 | thisChannelName) |
|
372 | thisChannelName) | |
372 | channelBoundList.append((start_index, end_index)) |
|
373 | channelBoundList.append((start_index, end_index)) | |
373 | channelNameListFiltered.append(thisChannelName) |
|
374 | channelNameListFiltered.append(thisChannelName) | |
374 |
|
375 | |||
375 | self.profileIndex = 0 |
|
376 | self.profileIndex = 0 | |
376 | self.i = 0 |
|
377 | self.i = 0 | |
377 | self.__delay = delay |
|
378 | self.__delay = delay | |
378 |
|
379 | |||
379 | self.__codeType = codeType |
|
380 | self.__codeType = codeType | |
380 | self.__nCode = nCode |
|
381 | self.__nCode = nCode | |
381 | self.__nBaud = nBaud |
|
382 | self.__nBaud = nBaud | |
382 | self.__code = code |
|
383 | self.__code = code | |
383 |
|
384 | |||
384 | self.__datapath = path |
|
385 | self.__datapath = path | |
385 | self.__online = online |
|
386 | self.__online = online | |
386 | self.__channelList = channelList |
|
387 | self.__channelList = channelList | |
387 | self.__channelNameList = channelNameListFiltered |
|
388 | self.__channelNameList = channelNameListFiltered | |
388 | self.__channelBoundList = channelBoundList |
|
389 | self.__channelBoundList = channelBoundList | |
389 | self.__nSamples = nSamples |
|
390 | self.__nSamples = nSamples | |
390 | self.__samples_to_read = long(nSamples) # FIJO: AHORA 40 |
|
391 | self.__samples_to_read = long(nSamples) # FIJO: AHORA 40 | |
391 | self.__nChannels = len(self.__channelList) |
|
392 | self.__nChannels = len(self.__channelList) | |
392 |
|
393 | |||
393 | self.__startUTCSecond = startUTCSecond |
|
394 | self.__startUTCSecond = startUTCSecond | |
394 | self.__endUTCSecond = endUTCSecond |
|
395 | self.__endUTCSecond = endUTCSecond | |
395 |
|
396 | |||
396 | self.__timeInterval = 1.0 * self.__samples_to_read / \ |
|
397 | self.__timeInterval = 1.0 * self.__samples_to_read / \ | |
397 | self.__sample_rate # Time interval |
|
398 | self.__sample_rate # Time interval | |
398 |
|
399 | |||
399 | if online: |
|
400 | if online: | |
400 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) |
|
401 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) | |
401 | startUTCSecond = numpy.floor(endUTCSecond) |
|
402 | startUTCSecond = numpy.floor(endUTCSecond) | |
402 |
|
403 | |||
403 | # por que en el otro metodo lo primero q se hace es sumar samplestoread |
|
404 | # por que en el otro metodo lo primero q se hace es sumar samplestoread | |
404 | self.__thisUnixSample = long( |
|
405 | self.__thisUnixSample = long( | |
405 | startUTCSecond * self.__sample_rate) - self.__samples_to_read |
|
406 | startUTCSecond * self.__sample_rate) - self.__samples_to_read | |
406 |
|
407 | |||
407 | self.__data_buffer = numpy.zeros( |
|
408 | self.__data_buffer = numpy.zeros( | |
408 | (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex) |
|
409 | (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex) | |
409 |
|
410 | |||
410 | self.__setFileHeader() |
|
411 | self.__setFileHeader() | |
411 | self.isConfig = True |
|
412 | self.isConfig = True | |
412 |
|
413 | |||
413 | print "[Reading] Digital RF Data was found from %s to %s " % ( |
|
414 | print "[Reading] Digital RF Data was found from %s to %s " % ( | |
414 | datetime.datetime.utcfromtimestamp( |
|
415 | datetime.datetime.utcfromtimestamp( | |
415 | self.__startUTCSecond - self.__timezone), |
|
416 | self.__startUTCSecond - self.__timezone), | |
416 | datetime.datetime.utcfromtimestamp( |
|
417 | datetime.datetime.utcfromtimestamp( | |
417 | self.__endUTCSecond - self.__timezone) |
|
418 | self.__endUTCSecond - self.__timezone) | |
418 | ) |
|
419 | ) | |
419 |
|
420 | |||
420 | print "[Reading] Starting process from %s to %s" % (datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), |
|
421 | print "[Reading] Starting process from %s to %s" % (datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), | |
421 | datetime.datetime.utcfromtimestamp( |
|
422 | datetime.datetime.utcfromtimestamp( | |
422 | endUTCSecond - self.__timezone) |
|
423 | endUTCSecond - self.__timezone) | |
423 | ) |
|
424 | ) | |
424 | self.oldAverage = None |
|
425 | self.oldAverage = None | |
425 | self.count = 0 |
|
426 | self.count = 0 | |
426 | self.executionTime = 0 |
|
427 | self.executionTime = 0 | |
427 |
|
428 | |||
428 | def __reload(self): |
|
429 | def __reload(self): | |
429 |
|
430 | |||
430 | # print "%s not in range [%s, %s]" %( |
|
431 | # print "%s not in range [%s, %s]" %( | |
431 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
432 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
432 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), |
|
433 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
433 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) |
|
434 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
434 | # ) |
|
435 | # ) | |
435 | print "[Reading] reloading metadata ..." |
|
436 | print "[Reading] reloading metadata ..." | |
436 |
|
437 | |||
437 | try: |
|
438 | try: | |
438 | self.digitalReadObj.reload(complete_update=True) |
|
439 | self.digitalReadObj.reload(complete_update=True) | |
439 | except: |
|
440 | except: | |
440 | self.digitalReadObj.reload() |
|
441 | self.digitalReadObj.reload() | |
441 |
|
442 | |||
442 | start_index, end_index = self.digitalReadObj.get_bounds( |
|
443 | start_index, end_index = self.digitalReadObj.get_bounds( | |
443 | self.__channelNameList[self.__channelList[0]]) |
|
444 | self.__channelNameList[self.__channelList[0]]) | |
444 |
|
445 | |||
445 | if start_index > self.__startUTCSecond * self.__sample_rate: |
|
446 | if start_index > self.__startUTCSecond * self.__sample_rate: | |
446 | self.__startUTCSecond = 1.0 * start_index / self.__sample_rate |
|
447 | self.__startUTCSecond = 1.0 * start_index / self.__sample_rate | |
447 |
|
448 | |||
448 | if end_index > self.__endUTCSecond * self.__sample_rate: |
|
449 | if end_index > self.__endUTCSecond * self.__sample_rate: | |
449 | self.__endUTCSecond = 1.0 * end_index / self.__sample_rate |
|
450 | self.__endUTCSecond = 1.0 * end_index / self.__sample_rate | |
450 |
|
451 | |||
451 | print "[Reading] New timerange found [%s, %s] " % ( |
|
452 | print "[Reading] New timerange found [%s, %s] " % ( | |
452 | datetime.datetime.utcfromtimestamp( |
|
453 | datetime.datetime.utcfromtimestamp( | |
453 | self.__startUTCSecond - self.__timezone), |
|
454 | self.__startUTCSecond - self.__timezone), | |
454 | datetime.datetime.utcfromtimestamp( |
|
455 | datetime.datetime.utcfromtimestamp( | |
455 | self.__endUTCSecond - self.__timezone) |
|
456 | self.__endUTCSecond - self.__timezone) | |
456 | ) |
|
457 | ) | |
457 |
|
458 | |||
458 | return True |
|
459 | return True | |
459 |
|
460 | |||
460 | return False |
|
461 | return False | |
461 |
|
462 | |||
462 | def timeit(self, toExecute): |
|
463 | def timeit(self, toExecute): | |
463 | t0 = time() |
|
464 | t0 = time() | |
464 | toExecute() |
|
465 | toExecute() | |
465 | self.executionTime = time() - t0 |
|
466 | self.executionTime = time() - t0 | |
466 | if self.oldAverage is None: |
|
467 | if self.oldAverage is None: | |
467 | self.oldAverage = self.executionTime |
|
468 | self.oldAverage = self.executionTime | |
468 | self.oldAverage = (self.executionTime + self.count * |
|
469 | self.oldAverage = (self.executionTime + self.count * | |
469 | self.oldAverage) / (self.count + 1.0) |
|
470 | self.oldAverage) / (self.count + 1.0) | |
470 | self.count = self.count + 1.0 |
|
471 | self.count = self.count + 1.0 | |
471 | return |
|
472 | return | |
472 |
|
473 | |||
473 | def __readNextBlock(self, seconds=30, volt_scale=1): |
|
474 | def __readNextBlock(self, seconds=30, volt_scale=1): | |
474 | ''' |
|
475 | ''' | |
475 | ''' |
|
476 | ''' | |
476 |
|
477 | |||
477 | # Set the next data |
|
478 | # Set the next data | |
478 | self.__flagDiscontinuousBlock = False |
|
479 | self.__flagDiscontinuousBlock = False | |
479 | self.__thisUnixSample += self.__samples_to_read |
|
480 | self.__thisUnixSample += self.__samples_to_read | |
480 |
|
481 | |||
481 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: |
|
482 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: | |
482 | print "[Reading] There are no more data into selected time-range" |
|
483 | print "[Reading] There are no more data into selected time-range" | |
483 | if self.__online: |
|
484 | if self.__online: | |
484 | self.__reload() |
|
485 | self.__reload() | |
485 | else: |
|
486 | else: | |
486 | return False |
|
487 | return False | |
487 |
|
488 | |||
488 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: |
|
489 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: | |
489 | return False |
|
490 | return False | |
490 | self.__thisUnixSample -= self.__samples_to_read |
|
491 | self.__thisUnixSample -= self.__samples_to_read | |
491 |
|
492 | |||
492 | indexChannel = 0 |
|
493 | indexChannel = 0 | |
493 |
|
494 | |||
494 | dataOk = False |
|
495 | dataOk = False | |
495 | for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS? |
|
496 | for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS? | |
496 | for indexSubchannel in range(self.__num_subchannels): |
|
497 | for indexSubchannel in range(self.__num_subchannels): | |
497 | try: |
|
498 | try: | |
498 | t0 = time() |
|
499 | t0 = time() | |
499 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, |
|
500 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, | |
500 | self.__samples_to_read, |
|
501 | self.__samples_to_read, | |
501 | thisChannelName, sub_channel=indexSubchannel) |
|
502 | thisChannelName, sub_channel=indexSubchannel) | |
502 | self.executionTime = time() - t0 |
|
503 | self.executionTime = time() - t0 | |
503 | if self.oldAverage is None: |
|
504 | if self.oldAverage is None: | |
504 | self.oldAverage = self.executionTime |
|
505 | self.oldAverage = self.executionTime | |
505 | self.oldAverage = ( |
|
506 | self.oldAverage = ( | |
506 | self.executionTime + self.count * self.oldAverage) / (self.count + 1.0) |
|
507 | self.executionTime + self.count * self.oldAverage) / (self.count + 1.0) | |
507 | self.count = self.count + 1.0 |
|
508 | self.count = self.count + 1.0 | |
508 |
|
509 | |||
509 | except IOError, e: |
|
510 | except IOError, e: | |
510 | # read next profile |
|
511 | # read next profile | |
511 | self.__flagDiscontinuousBlock = True |
|
512 | self.__flagDiscontinuousBlock = True | |
512 | print "[Reading] %s" % datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e |
|
513 | print "[Reading] %s" % datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e | |
513 | break |
|
514 | break | |
514 |
|
515 | |||
515 | if result.shape[0] != self.__samples_to_read: |
|
516 | if result.shape[0] != self.__samples_to_read: | |
516 | self.__flagDiscontinuousBlock = True |
|
517 | self.__flagDiscontinuousBlock = True | |
517 | print "[Reading] %s: Too few samples were found, just %d/%d samples" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
518 | print "[Reading] %s: Too few samples were found, just %d/%d samples" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
518 | result.shape[0], |
|
519 | result.shape[0], | |
519 | self.__samples_to_read) |
|
520 | self.__samples_to_read) | |
520 | break |
|
521 | break | |
521 |
|
522 | |||
522 | self.__data_buffer[indexSubchannel, :] = result * volt_scale |
|
523 | self.__data_buffer[indexSubchannel, :] = result * volt_scale | |
523 |
|
524 | |||
524 | indexChannel += 1 |
|
525 | indexChannel += 1 | |
525 |
|
526 | |||
526 | dataOk = True |
|
527 | dataOk = True | |
527 |
|
528 | |||
528 | self.__utctime = self.__thisUnixSample / self.__sample_rate |
|
529 | self.__utctime = self.__thisUnixSample / self.__sample_rate | |
529 |
|
530 | |||
530 | if not dataOk: |
|
531 | if not dataOk: | |
531 | return False |
|
532 | return False | |
532 |
|
533 | |||
533 | print "[Reading] %s: %d samples <> %f sec" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
534 | print "[Reading] %s: %d samples <> %f sec" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
534 | self.__samples_to_read, |
|
535 | self.__samples_to_read, | |
535 | self.__timeInterval) |
|
536 | self.__timeInterval) | |
536 |
|
537 | |||
537 | self.__bufferIndex = 0 |
|
538 | self.__bufferIndex = 0 | |
538 |
|
539 | |||
539 | return True |
|
540 | return True | |
540 |
|
541 | |||
541 | def __isBufferEmpty(self): |
|
542 | def __isBufferEmpty(self): | |
542 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples # 40960 - 40 |
|
543 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples # 40960 - 40 | |
543 |
|
544 | |||
544 | def getData(self, seconds=30, nTries=5): |
|
545 | def getData(self, seconds=30, nTries=5): | |
545 | ''' |
|
546 | ''' | |
546 | This method gets the data from files and put the data into the dataOut object |
|
547 | This method gets the data from files and put the data into the dataOut object | |
547 |
|
548 | |||
548 | In addition, increase el the buffer counter in one. |
|
549 | In addition, increase el the buffer counter in one. | |
549 |
|
550 | |||
550 | Return: |
|
551 | Return: | |
551 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
552 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
552 | buffer. Si no hay mas archivos a leer retorna None. |
|
553 | buffer. Si no hay mas archivos a leer retorna None. | |
553 |
|
554 | |||
554 | Affected: |
|
555 | Affected: | |
555 | self.dataOut |
|
556 | self.dataOut | |
556 | self.profileIndex |
|
557 | self.profileIndex | |
557 | self.flagDiscontinuousBlock |
|
558 | self.flagDiscontinuousBlock | |
558 | self.flagIsNewBlock |
|
559 | self.flagIsNewBlock | |
559 | ''' |
|
560 | ''' | |
560 |
|
561 | |||
561 | err_counter = 0 |
|
562 | err_counter = 0 | |
562 | self.dataOut.flagNoData = True |
|
563 | self.dataOut.flagNoData = True | |
563 |
|
564 | |||
564 | if self.__isBufferEmpty(): |
|
565 | if self.__isBufferEmpty(): | |
565 | self.__flagDiscontinuousBlock = False |
|
566 | self.__flagDiscontinuousBlock = False | |
566 |
|
567 | |||
567 | while True: |
|
568 | while True: | |
568 | if self.__readNextBlock(): |
|
569 | if self.__readNextBlock(): | |
569 | break |
|
570 | break | |
570 | if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate: |
|
571 | if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate: | |
571 | return False |
|
572 | return False | |
572 |
|
573 | |||
573 | if self.__flagDiscontinuousBlock: |
|
574 | if self.__flagDiscontinuousBlock: | |
574 | print '[Reading] discontinuous block found ... continue with the next block' |
|
575 | print '[Reading] discontinuous block found ... continue with the next block' | |
575 | continue |
|
576 | continue | |
576 |
|
577 | |||
577 | if not self.__online: |
|
578 | if not self.__online: | |
578 | return False |
|
579 | return False | |
579 |
|
580 | |||
580 | err_counter += 1 |
|
581 | err_counter += 1 | |
581 | if err_counter > nTries: |
|
582 | if err_counter > nTries: | |
582 | return False |
|
583 | return False | |
583 |
|
584 | |||
584 | print '[Reading] waiting %d seconds to read a new block' % seconds |
|
585 | print '[Reading] waiting %d seconds to read a new block' % seconds | |
585 | sleep(seconds) |
|
586 | sleep(seconds) | |
586 |
|
587 | |||
587 | self.dataOut.data = self.__data_buffer[:, |
|
588 | self.dataOut.data = self.__data_buffer[:, | |
588 | self.__bufferIndex:self.__bufferIndex + self.__nSamples] |
|
589 | self.__bufferIndex:self.__bufferIndex + self.__nSamples] | |
589 | self.dataOut.utctime = ( |
|
590 | self.dataOut.utctime = ( | |
590 | self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate |
|
591 | self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate | |
591 | self.dataOut.flagNoData = False |
|
592 | self.dataOut.flagNoData = False | |
592 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock |
|
593 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock | |
593 | self.dataOut.profileIndex = self.profileIndex |
|
594 | self.dataOut.profileIndex = self.profileIndex | |
594 |
|
595 | |||
595 | self.__bufferIndex += self.__nSamples |
|
596 | self.__bufferIndex += self.__nSamples | |
596 | self.profileIndex += 1 |
|
597 | self.profileIndex += 1 | |
597 |
|
598 | |||
598 | if self.profileIndex == self.dataOut.nProfiles: |
|
599 | if self.profileIndex == self.dataOut.nProfiles: | |
599 | self.profileIndex = 0 |
|
600 | self.profileIndex = 0 | |
600 |
|
601 | |||
601 | return True |
|
602 | return True | |
602 |
|
603 | |||
603 | def printInfo(self): |
|
604 | def printInfo(self): | |
604 | ''' |
|
605 | ''' | |
605 | ''' |
|
606 | ''' | |
606 | if self.__printInfo == False: |
|
607 | if self.__printInfo == False: | |
607 | return |
|
608 | return | |
608 |
|
609 | |||
609 | # self.systemHeaderObj.printInfo() |
|
610 | # self.systemHeaderObj.printInfo() | |
610 | # self.radarControllerHeaderObj.printInfo() |
|
611 | # self.radarControllerHeaderObj.printInfo() | |
611 |
|
612 | |||
612 | self.__printInfo = False |
|
613 | self.__printInfo = False | |
613 |
|
614 | |||
614 | def printNumberOfBlock(self): |
|
615 | def printNumberOfBlock(self): | |
615 | ''' |
|
616 | ''' | |
616 | ''' |
|
617 | ''' | |
617 | return |
|
618 | return | |
618 | # print self.profileIndex |
|
619 | # print self.profileIndex | |
619 |
|
620 | |||
620 | def run(self, **kwargs): |
|
621 | def run(self, **kwargs): | |
621 | ''' |
|
622 | ''' | |
622 | This method will be called many times so here you should put all your code |
|
623 | This method will be called many times so here you should put all your code | |
623 | ''' |
|
624 | ''' | |
624 |
|
625 | |||
625 | if not self.isConfig: |
|
626 | if not self.isConfig: | |
626 | self.setup(**kwargs) |
|
627 | self.setup(**kwargs) | |
627 | #self.i = self.i+1 |
|
628 | #self.i = self.i+1 | |
628 | self.getData(seconds=self.__delay) |
|
629 | self.getData(seconds=self.__delay) | |
629 |
|
630 | |||
630 | return |
|
631 | return | |
631 |
|
632 | |||
632 |
|
633 | |||
633 | class DigitalRFWriter(Operation): |
|
634 | class DigitalRFWriter(Operation): | |
634 | ''' |
|
635 | ''' | |
635 | classdocs |
|
636 | classdocs | |
636 | ''' |
|
637 | ''' | |
637 |
|
638 | |||
638 | def __init__(self, **kwargs): |
|
639 | def __init__(self, **kwargs): | |
639 | ''' |
|
640 | ''' | |
640 | Constructor |
|
641 | Constructor | |
641 | ''' |
|
642 | ''' | |
642 | Operation.__init__(self, **kwargs) |
|
643 | Operation.__init__(self, **kwargs) | |
643 | self.metadata_dict = {} |
|
644 | self.metadata_dict = {} | |
644 | self.dataOut = None |
|
645 | self.dataOut = None | |
645 | self.dtype = None |
|
646 | self.dtype = None | |
|
647 | self.oldAverage = 0 | |||
646 |
|
648 | |||
647 | def setHeader(self): |
|
649 | def setHeader(self): | |
648 |
|
650 | |||
649 | self.metadata_dict['frequency'] = self.dataOut.frequency |
|
651 | self.metadata_dict['frequency'] = self.dataOut.frequency | |
650 | self.metadata_dict['timezone'] = self.dataOut.timeZone |
|
652 | self.metadata_dict['timezone'] = self.dataOut.timeZone | |
651 | self.metadata_dict['dtype'] = cPickle.dumps(self.dataOut.dtype) |
|
653 | self.metadata_dict['dtype'] = cPickle.dumps(self.dataOut.dtype) | |
652 | self.metadata_dict['nProfiles'] = self.dataOut.nProfiles |
|
654 | self.metadata_dict['nProfiles'] = self.dataOut.nProfiles | |
653 | self.metadata_dict['heightList'] = self.dataOut.heightList |
|
655 | self.metadata_dict['heightList'] = self.dataOut.heightList | |
654 | self.metadata_dict['channelList'] = self.dataOut.channelList |
|
656 | self.metadata_dict['channelList'] = self.dataOut.channelList | |
655 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData |
|
657 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData | |
656 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData |
|
658 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData | |
657 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT |
|
659 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT | |
658 | self.metadata_dict['flagDataAsBlock'] = self.dataOut.flagDataAsBlock |
|
660 | self.metadata_dict['flagDataAsBlock'] = self.dataOut.flagDataAsBlock | |
659 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime |
|
661 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime | |
660 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt |
|
662 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt | |
661 |
|
663 | |||
662 | return |
|
664 | return | |
663 |
|
665 | |||
664 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): |
|
666 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): | |
665 | ''' |
|
667 | ''' | |
666 | In this method we should set all initial parameters. |
|
668 | In this method we should set all initial parameters. | |
667 | Input: |
|
669 | Input: | |
668 | dataOut: Input data will also be outputa data |
|
670 | dataOut: Input data will also be outputa data | |
669 | ''' |
|
671 | ''' | |
670 | self.setHeader() |
|
672 | self.setHeader() | |
671 | self.__ippSeconds = dataOut.ippSeconds |
|
673 | self.__ippSeconds = dataOut.ippSeconds | |
672 | self.__deltaH = dataOut.getDeltaH() |
|
674 | self.__deltaH = dataOut.getDeltaH() | |
673 | self.__sample_rate = 1e6 * 0.15 / self.__deltaH |
|
675 | self.__sample_rate = 1e6 * 0.15 / self.__deltaH | |
674 | self.__dtype = dataOut.dtype |
|
676 | self.__dtype = dataOut.dtype | |
675 | if len(dataOut.dtype) == 2: |
|
677 | if len(dataOut.dtype) == 2: | |
676 | self.__dtype = dataOut.dtype[0] |
|
678 | self.__dtype = dataOut.dtype[0] | |
677 | self.__nSamples = dataOut.systemHeaderObj.nSamples |
|
679 | self.__nSamples = dataOut.systemHeaderObj.nSamples | |
678 | self.__nProfiles = dataOut.nProfiles |
|
680 | self.__nProfiles = dataOut.nProfiles | |
679 | self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile |
|
681 | self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile | |
680 |
|
682 | |||
681 | self.arr_data = arr_data = numpy.ones((self.__nSamples, len( |
|
683 | self.arr_data = arr_data = numpy.ones((self.__nSamples, len( | |
682 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) |
|
684 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) | |
683 |
|
685 | |||
684 |
file_cadence_millisecs = |
|
686 | file_cadence_millisecs = 1000 | |
685 | 1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate) * 1000 |
|
|||
686 | sub_cadence_secs = file_cadence_millisecs / 500 |
|
|||
687 |
|
687 | |||
688 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() |
|
688 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() | |
689 | sample_rate_numerator = long(sample_rate_fraction.numerator) |
|
689 | sample_rate_numerator = long(sample_rate_fraction.numerator) | |
690 | sample_rate_denominator = long(sample_rate_fraction.denominator) |
|
690 | sample_rate_denominator = long(sample_rate_fraction.denominator) | |
691 | start_global_index = dataOut.utctime * self.__sample_rate |
|
691 | start_global_index = dataOut.utctime * self.__sample_rate | |
692 |
|
692 | |||
693 | uuid = 'prueba' |
|
693 | uuid = 'prueba' | |
694 |
compression_level = |
|
694 | compression_level = 0 | |
695 | checksum = False |
|
695 | checksum = False | |
696 | is_complex = True |
|
696 | is_complex = True | |
697 | num_subchannels = len(dataOut.channelList) |
|
697 | num_subchannels = len(dataOut.channelList) | |
698 | is_continuous = True |
|
698 | is_continuous = True | |
699 | marching_periods = False |
|
699 | marching_periods = False | |
700 |
|
700 | |||
701 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence, |
|
701 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence, | |
702 | fileCadence, start_global_index, |
|
702 | fileCadence, start_global_index, | |
703 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, |
|
703 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, | |
704 | is_complex, num_subchannels, is_continuous, marching_periods) |
|
704 | is_complex, num_subchannels, is_continuous, marching_periods) | |
705 |
|
705 | |||
706 | metadata_dir = os.path.join(path, 'metadata') |
|
706 | metadata_dir = os.path.join(path, 'metadata') | |
707 | os.system('mkdir %s' % (metadata_dir)) |
|
707 | os.system('mkdir %s' % (metadata_dir)) | |
708 |
|
708 | |||
709 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 |
|
709 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 | |
710 | sample_rate_numerator, sample_rate_denominator, |
|
710 | sample_rate_numerator, sample_rate_denominator, | |
711 | metadataFile) |
|
711 | metadataFile) | |
712 |
|
712 | |||
713 | self.isConfig = True |
|
713 | self.isConfig = True | |
714 | self.currentSample = 0 |
|
714 | self.currentSample = 0 | |
715 | self.oldAverage = 0 |
|
715 | self.oldAverage = 0 | |
716 | self.count = 0 |
|
716 | self.count = 0 | |
717 | return |
|
717 | return | |
718 |
|
718 | |||
719 | def writeMetadata(self): |
|
719 | def writeMetadata(self): | |
720 | print '[Writing] - Writing metadata' |
|
720 | print '[Writing] - Writing metadata' | |
721 | start_idx = self.__sample_rate * self.dataOut.utctime |
|
721 | start_idx = self.__sample_rate * self.dataOut.utctime | |
722 |
|
722 | |||
723 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( |
|
723 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( | |
724 | ) |
|
724 | ) | |
725 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict( |
|
725 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict( | |
726 | ) |
|
726 | ) | |
727 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict( |
|
727 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict( | |
728 | ) |
|
728 | ) | |
729 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) |
|
729 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) | |
730 | return |
|
730 | return | |
731 |
|
731 | |||
732 | def timeit(self, toExecute): |
|
732 | def timeit(self, toExecute): | |
733 | t0 = time() |
|
733 | t0 = time() | |
734 | toExecute() |
|
734 | toExecute() | |
735 | self.executionTime = time() - t0 |
|
735 | self.executionTime = time() - t0 | |
736 | if self.oldAverage is None: |
|
736 | if self.oldAverage is None: | |
737 | self.oldAverage = self.executionTime |
|
737 | self.oldAverage = self.executionTime | |
738 | self.oldAverage = (self.executionTime + self.count * |
|
738 | self.oldAverage = (self.executionTime + self.count * | |
739 | self.oldAverage) / (self.count + 1.0) |
|
739 | self.oldAverage) / (self.count + 1.0) | |
740 | self.count = self.count + 1.0 |
|
740 | self.count = self.count + 1.0 | |
741 | return |
|
741 | return | |
742 |
|
742 | |||
743 | def writeData(self): |
|
743 | def writeData(self): | |
744 | for i in range(self.dataOut.systemHeaderObj.nSamples): |
|
744 | for i in range(self.dataOut.systemHeaderObj.nSamples): | |
745 | for channel in self.dataOut.channelList: |
|
745 | for channel in self.dataOut.channelList: | |
746 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real |
|
746 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real | |
747 | self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag |
|
747 | self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag | |
748 |
|
748 | |||
749 | def f(): return self.digitalWriteObj.rf_write(self.arr_data) |
|
749 | def f(): return self.digitalWriteObj.rf_write(self.arr_data) | |
750 | self.timeit(f) |
|
750 | self.timeit(f) | |
751 |
|
751 | |||
752 | return |
|
752 | return | |
753 |
|
753 | |||
754 |
def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=100, dirCadence= |
|
754 | def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=1000, dirCadence=36000, metadataCadence=1, **kwargs): | |
755 | ''' |
|
755 | ''' | |
756 | This method will be called many times so here you should put all your code |
|
756 | This method will be called many times so here you should put all your code | |
757 | Inputs: |
|
757 | Inputs: | |
758 | dataOut: object with the data |
|
758 | dataOut: object with the data | |
759 | ''' |
|
759 | ''' | |
760 | # print dataOut.__dict__ |
|
760 | # print dataOut.__dict__ | |
761 | self.dataOut = dataOut |
|
761 | self.dataOut = dataOut | |
762 | if not self.isConfig: |
|
762 | if not self.isConfig: | |
763 | self.setup(dataOut, path, frequency, fileCadence, |
|
763 | self.setup(dataOut, path, frequency, fileCadence, | |
764 | dirCadence, metadataCadence, **kwargs) |
|
764 | dirCadence, metadataCadence, **kwargs) | |
765 | self.writeMetadata() |
|
765 | self.writeMetadata() | |
766 |
|
766 | |||
767 | self.writeData() |
|
767 | self.writeData() | |
768 |
|
768 | |||
769 | ## self.currentSample += 1 |
|
769 | ## self.currentSample += 1 | |
770 | # if self.dataOut.flagDataAsBlock or self.currentSample == 1: |
|
770 | # if self.dataOut.flagDataAsBlock or self.currentSample == 1: | |
771 | # self.writeMetadata() |
|
771 | # self.writeMetadata() | |
772 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 |
|
772 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 | |
773 |
|
773 | |||
774 | def close(self): |
|
774 | def close(self): | |
775 | print '[Writing] - Closing files ' |
|
775 | print '[Writing] - Closing files ' | |
776 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 |
|
776 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 | |
777 | try: |
|
777 | try: | |
778 | self.digitalWriteObj.close() |
|
778 | self.digitalWriteObj.close() | |
779 | except: |
|
779 | except: | |
780 | pass |
|
780 | pass | |
781 |
|
781 | |||
|
782 | ||||
782 | # raise |
|
783 | # raise | |
783 | if __name__ == '__main__': |
|
784 | if __name__ == '__main__': | |
784 |
|
785 | |||
785 | readObj = DigitalRFReader() |
|
786 | readObj = DigitalRFReader() | |
786 |
|
787 | |||
787 | while True: |
|
788 | while True: | |
788 | readObj.run(path='/home/jchavez/jicamarca/mocked_data/') |
|
789 | readObj.run(path='/home/jchavez/jicamarca/mocked_data/') | |
789 | # readObj.printInfo() |
|
790 | # readObj.printInfo() | |
790 | # readObj.printNumberOfBlock() |
|
791 | # readObj.printNumberOfBlock() |
@@ -1,762 +1,764 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 2, 2014 |
|
2 | Created on Jul 2, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import numpy |
|
7 | import numpy | |
8 |
|
8 | |||
9 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter |
|
9 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter | |
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
11 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader |
|
11 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
12 | from schainpy.model.data.jrodata import Voltage |
|
12 | from schainpy.model.data.jrodata import Voltage | |
13 | import zmq |
|
13 | import zmq | |
14 | import tempfile |
|
14 | import tempfile | |
15 | from StringIO import StringIO |
|
15 | from StringIO import StringIO | |
16 | # from _sha import blocksize |
|
16 | # from _sha import blocksize | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | class VoltageReader(JRODataReader, ProcessingUnit): |
|
19 | class VoltageReader(JRODataReader, ProcessingUnit): | |
20 | """ |
|
20 | """ | |
21 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
21 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
22 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
22 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
23 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
23 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
24 |
|
24 | |||
25 | perfiles * alturas * canales |
|
25 | perfiles * alturas * canales | |
26 |
|
26 | |||
27 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
27 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
28 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
28 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
29 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
29 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
30 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
30 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
31 |
|
31 | |||
32 | Example: |
|
32 | Example: | |
33 |
|
33 | |||
34 | dpath = "/home/myuser/data" |
|
34 | dpath = "/home/myuser/data" | |
35 |
|
35 | |||
36 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
36 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
37 |
|
37 | |||
38 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
38 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
39 |
|
39 | |||
40 | readerObj = VoltageReader() |
|
40 | readerObj = VoltageReader() | |
41 |
|
41 | |||
42 | readerObj.setup(dpath, startTime, endTime) |
|
42 | readerObj.setup(dpath, startTime, endTime) | |
43 |
|
43 | |||
44 | while(True): |
|
44 | while(True): | |
45 |
|
45 | |||
46 | #to get one profile |
|
46 | #to get one profile | |
47 | profile = readerObj.getData() |
|
47 | profile = readerObj.getData() | |
48 |
|
48 | |||
49 | #print the profile |
|
49 | #print the profile | |
50 | print profile |
|
50 | print profile | |
51 |
|
51 | |||
52 | #If you want to see all datablock |
|
52 | #If you want to see all datablock | |
53 | print readerObj.datablock |
|
53 | print readerObj.datablock | |
54 |
|
54 | |||
55 | if readerObj.flagNoMoreFiles: |
|
55 | if readerObj.flagNoMoreFiles: | |
56 | break |
|
56 | break | |
57 |
|
57 | |||
58 | """ |
|
58 | """ | |
59 |
|
59 | |||
60 | ext = ".r" |
|
60 | ext = ".r" | |
61 |
|
61 | |||
62 | optchar = "D" |
|
62 | optchar = "D" | |
63 | dataOut = None |
|
63 | dataOut = None | |
64 |
|
64 | |||
65 | def __init__(self, **kwargs): |
|
65 | def __init__(self, **kwargs): | |
66 | """ |
|
66 | """ | |
67 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
67 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
68 |
|
68 | |||
69 | Input: |
|
69 | Input: | |
70 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
70 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
71 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
71 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
72 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
72 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
73 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
73 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
74 | bloque de datos. |
|
74 | bloque de datos. | |
75 | Si este parametro no es pasado se creara uno internamente. |
|
75 | Si este parametro no es pasado se creara uno internamente. | |
76 |
|
76 | |||
77 | Variables afectadas: |
|
77 | Variables afectadas: | |
78 | self.dataOut |
|
78 | self.dataOut | |
79 |
|
79 | |||
80 | Return: |
|
80 | Return: | |
81 | None |
|
81 | None | |
82 | """ |
|
82 | """ | |
83 |
|
83 | |||
84 | ProcessingUnit.__init__(self, **kwargs) |
|
84 | ProcessingUnit.__init__(self, **kwargs) | |
85 |
|
85 | |||
86 | self.isConfig = False |
|
86 | self.isConfig = False | |
87 |
|
87 | |||
88 | self.datablock = None |
|
88 | self.datablock = None | |
89 |
|
89 | |||
90 | self.utc = 0 |
|
90 | self.utc = 0 | |
91 |
|
91 | |||
92 | self.ext = ".r" |
|
92 | self.ext = ".r" | |
93 |
|
93 | |||
94 | self.optchar = "D" |
|
94 | self.optchar = "D" | |
95 |
|
95 | |||
96 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
96 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
97 |
|
97 | |||
98 | self.systemHeaderObj = SystemHeader() |
|
98 | self.systemHeaderObj = SystemHeader() | |
99 |
|
99 | |||
100 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
100 | self.radarControllerHeaderObj = RadarControllerHeader() | |
101 |
|
101 | |||
102 | self.processingHeaderObj = ProcessingHeader() |
|
102 | self.processingHeaderObj = ProcessingHeader() | |
103 |
|
103 | |||
104 | self.online = 0 |
|
104 | self.online = 0 | |
105 |
|
105 | |||
106 | self.fp = None |
|
106 | self.fp = None | |
107 |
|
107 | |||
108 | self.idFile = None |
|
108 | self.idFile = None | |
109 |
|
109 | |||
110 | self.dtype = None |
|
110 | self.dtype = None | |
111 |
|
111 | |||
112 | self.fileSizeByHeader = None |
|
112 | self.fileSizeByHeader = None | |
113 |
|
113 | |||
114 | self.filenameList = [] |
|
114 | self.filenameList = [] | |
115 |
|
115 | |||
116 | self.filename = None |
|
116 | self.filename = None | |
117 |
|
117 | |||
118 | self.fileSize = None |
|
118 | self.fileSize = None | |
119 |
|
119 | |||
120 | self.firstHeaderSize = 0 |
|
120 | self.firstHeaderSize = 0 | |
121 |
|
121 | |||
122 | self.basicHeaderSize = 24 |
|
122 | self.basicHeaderSize = 24 | |
123 |
|
123 | |||
124 | self.pathList = [] |
|
124 | self.pathList = [] | |
125 |
|
125 | |||
126 | self.filenameList = [] |
|
126 | self.filenameList = [] | |
127 |
|
127 | |||
128 | self.lastUTTime = 0 |
|
128 | self.lastUTTime = 0 | |
129 |
|
129 | |||
130 | self.maxTimeStep = 30 |
|
130 | self.maxTimeStep = 30 | |
131 |
|
131 | |||
132 | self.flagNoMoreFiles = 0 |
|
132 | self.flagNoMoreFiles = 0 | |
133 |
|
133 | |||
134 | self.set = 0 |
|
134 | self.set = 0 | |
135 |
|
135 | |||
136 | self.path = None |
|
136 | self.path = None | |
137 |
|
137 | |||
138 | self.profileIndex = 2**32 - 1 |
|
138 | self.profileIndex = 2**32 - 1 | |
139 |
|
139 | |||
140 | self.delay = 3 # seconds |
|
140 | self.delay = 3 # seconds | |
141 |
|
141 | |||
142 | self.nTries = 3 # quantity tries |
|
142 | self.nTries = 3 # quantity tries | |
143 |
|
143 | |||
144 | self.nFiles = 3 # number of files for searching |
|
144 | self.nFiles = 3 # number of files for searching | |
145 |
|
145 | |||
146 | self.nReadBlocks = 0 |
|
146 | self.nReadBlocks = 0 | |
147 |
|
147 | |||
148 | self.flagIsNewFile = 1 |
|
148 | self.flagIsNewFile = 1 | |
149 |
|
149 | |||
150 | self.__isFirstTimeOnline = 1 |
|
150 | self.__isFirstTimeOnline = 1 | |
151 |
|
151 | |||
152 | # self.ippSeconds = 0 |
|
152 | # self.ippSeconds = 0 | |
153 |
|
153 | |||
154 | self.flagDiscontinuousBlock = 0 |
|
154 | self.flagDiscontinuousBlock = 0 | |
155 |
|
155 | |||
156 | self.flagIsNewBlock = 0 |
|
156 | self.flagIsNewBlock = 0 | |
157 |
|
157 | |||
158 | self.nTotalBlocks = 0 |
|
158 | self.nTotalBlocks = 0 | |
159 |
|
159 | |||
160 | self.blocksize = 0 |
|
160 | self.blocksize = 0 | |
161 |
|
161 | |||
162 | self.dataOut = self.createObjByDefault() |
|
162 | self.dataOut = self.createObjByDefault() | |
163 |
|
163 | |||
164 | self.nTxs = 1 |
|
164 | self.nTxs = 1 | |
165 |
|
165 | |||
166 | self.txIndex = 0 |
|
166 | self.txIndex = 0 | |
167 |
|
167 | |||
168 | def createObjByDefault(self): |
|
168 | def createObjByDefault(self): | |
169 |
|
169 | |||
170 | dataObj = Voltage() |
|
170 | dataObj = Voltage() | |
171 |
|
171 | |||
172 | return dataObj |
|
172 | return dataObj | |
173 |
|
173 | |||
174 | def __hasNotDataInBuffer(self): |
|
174 | def __hasNotDataInBuffer(self): | |
175 |
|
175 | |||
176 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock * self.nTxs: |
|
176 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock * self.nTxs: | |
177 | return 1 |
|
177 | return 1 | |
178 |
|
178 | |||
179 | return 0 |
|
179 | return 0 | |
180 |
|
180 | |||
181 | def getBlockDimension(self): |
|
181 | def getBlockDimension(self): | |
182 | """ |
|
182 | """ | |
183 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
183 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
184 |
|
184 | |||
185 | Affected: |
|
185 | Affected: | |
186 | self.blocksize |
|
186 | self.blocksize | |
187 |
|
187 | |||
188 | Return: |
|
188 | Return: | |
189 | None |
|
189 | None | |
190 | """ |
|
190 | """ | |
191 | pts2read = self.processingHeaderObj.profilesPerBlock * \ |
|
191 | pts2read = self.processingHeaderObj.profilesPerBlock * \ | |
192 | self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
192 | self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
193 | self.blocksize = pts2read |
|
193 | self.blocksize = pts2read | |
194 |
|
194 | |||
195 | def readBlock(self): |
|
195 | def readBlock(self): | |
196 | """ |
|
196 | """ | |
197 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
197 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
198 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
198 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
199 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
199 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
200 | es seteado a 0 |
|
200 | es seteado a 0 | |
201 |
|
201 | |||
202 | Inputs: |
|
202 | Inputs: | |
203 | None |
|
203 | None | |
204 |
|
204 | |||
205 | Return: |
|
205 | Return: | |
206 | None |
|
206 | None | |
207 |
|
207 | |||
208 | Affected: |
|
208 | Affected: | |
209 | self.profileIndex |
|
209 | self.profileIndex | |
210 | self.datablock |
|
210 | self.datablock | |
211 | self.flagIsNewFile |
|
211 | self.flagIsNewFile | |
212 | self.flagIsNewBlock |
|
212 | self.flagIsNewBlock | |
213 | self.nTotalBlocks |
|
213 | self.nTotalBlocks | |
214 |
|
214 | |||
215 | Exceptions: |
|
215 | Exceptions: | |
216 | Si un bloque leido no es un bloque valido |
|
216 | Si un bloque leido no es un bloque valido | |
217 | """ |
|
217 | """ | |
218 |
|
218 | |||
219 | # if self.server is not None: |
|
219 | # if self.server is not None: | |
220 | # self.zBlock = self.receiver.recv() |
|
220 | # self.zBlock = self.receiver.recv() | |
221 | # self.zHeader = self.zBlock[:24] |
|
221 | # self.zHeader = self.zBlock[:24] | |
222 | # self.zDataBlock = self.zBlock[24:] |
|
222 | # self.zDataBlock = self.zBlock[24:] | |
223 | # junk = numpy.fromstring(self.zDataBlock, numpy.dtype([('real','<i4'),('imag','<i4')])) |
|
223 | # junk = numpy.fromstring(self.zDataBlock, numpy.dtype([('real','<i4'),('imag','<i4')])) | |
224 | # self.processingHeaderObj.profilesPerBlock = 240 |
|
224 | # self.processingHeaderObj.profilesPerBlock = 240 | |
225 | # self.processingHeaderObj.nHeights = 248 |
|
225 | # self.processingHeaderObj.nHeights = 248 | |
226 | # self.systemHeaderObj.nChannels |
|
226 | # self.systemHeaderObj.nChannels | |
227 | # else: |
|
227 | # else: | |
228 | current_pointer_location = self.fp.tell() |
|
228 | current_pointer_location = self.fp.tell() | |
229 | junk = numpy.fromfile(self.fp, self.dtype, self.blocksize) |
|
229 | junk = numpy.fromfile(self.fp, self.dtype, self.blocksize) | |
230 |
|
230 | |||
231 | try: |
|
231 | try: | |
232 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, |
|
232 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
233 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) |
|
233 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
234 | except: |
|
234 | except: | |
235 | # print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
235 | # print "The read block (%3d) has not enough data" %self.nReadBlocks | |
236 |
|
236 | |||
237 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
237 | if self.waitDataBlock(pointer_location=current_pointer_location): | |
238 | junk = numpy.fromfile(self.fp, self.dtype, self.blocksize) |
|
238 | junk = numpy.fromfile(self.fp, self.dtype, self.blocksize) | |
239 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, |
|
239 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
240 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) |
|
240 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
241 | # return 0 |
|
241 | # return 0 | |
242 |
|
242 | |||
243 | # Dimensions : nChannels, nProfiles, nSamples |
|
243 | # Dimensions : nChannels, nProfiles, nSamples | |
244 |
|
244 | |||
245 | junk = numpy.transpose(junk, (2, 0, 1)) |
|
245 | junk = numpy.transpose(junk, (2, 0, 1)) | |
246 | self.datablock = junk['real'] + junk['imag'] * 1j |
|
246 | self.datablock = junk['real'] + junk['imag'] * 1j | |
247 |
|
247 | |||
248 | self.profileIndex = 0 |
|
248 | self.profileIndex = 0 | |
249 |
|
249 | |||
250 | self.flagIsNewFile = 0 |
|
250 | self.flagIsNewFile = 0 | |
251 | self.flagIsNewBlock = 1 |
|
251 | self.flagIsNewBlock = 1 | |
252 |
|
252 | |||
253 | self.nTotalBlocks += 1 |
|
253 | self.nTotalBlocks += 1 | |
254 | self.nReadBlocks += 1 |
|
254 | self.nReadBlocks += 1 | |
255 |
|
255 | |||
256 | return 1 |
|
256 | return 1 | |
257 |
|
257 | |||
258 | def getFirstHeader(self): |
|
258 | def getFirstHeader(self): | |
259 |
|
259 | |||
260 | self.getBasicHeader() |
|
260 | self.getBasicHeader() | |
261 |
|
261 | |||
|
262 | self.dataOut.processingHeaderObj = self.processingHeaderObj.copy() | |||
|
263 | ||||
262 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
264 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
263 |
|
265 | |||
264 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
266 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
265 |
|
267 | |||
266 | if self.nTxs > 1: |
|
268 | if self.nTxs > 1: | |
267 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs |
|
269 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |
268 | # Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj. |
|
270 | # Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj. | |
269 |
|
271 | |||
270 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt |
|
272 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt | |
271 | # |
|
273 | # | |
272 | # if self.radarControllerHeaderObj.code is not None: |
|
274 | # if self.radarControllerHeaderObj.code is not None: | |
273 | # |
|
275 | # | |
274 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
276 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
275 | # |
|
277 | # | |
276 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
278 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
277 | # |
|
279 | # | |
278 | # self.dataOut.code = self.radarControllerHeaderObj.code |
|
280 | # self.dataOut.code = self.radarControllerHeaderObj.code | |
279 |
|
281 | |||
280 | self.dataOut.dtype = self.dtype |
|
282 | self.dataOut.dtype = self.dtype | |
281 |
|
283 | |||
282 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
284 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
283 |
|
285 | |||
284 | self.dataOut.heightList = numpy.arange( |
|
286 | self.dataOut.heightList = numpy.arange( | |
285 | self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight |
|
287 | self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
286 |
|
288 | |||
287 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
289 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
288 |
|
290 | |||
289 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
291 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
290 |
|
292 | |||
291 | # asumo q la data no esta decodificada |
|
293 | # asumo q la data no esta decodificada | |
292 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode |
|
294 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode | |
293 |
|
295 | |||
294 | # asumo q la data no esta sin flip |
|
296 | # asumo q la data no esta sin flip | |
295 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip |
|
297 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip | |
296 |
|
298 | |||
297 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
299 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |
298 |
|
300 | |||
299 | def reshapeData(self): |
|
301 | def reshapeData(self): | |
300 |
|
302 | |||
301 | if self.nTxs < 0: |
|
303 | if self.nTxs < 0: | |
302 | return |
|
304 | return | |
303 |
|
305 | |||
304 | if self.nTxs == 1: |
|
306 | if self.nTxs == 1: | |
305 | return |
|
307 | return | |
306 |
|
308 | |||
307 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1. / self.nTxs) != 0: |
|
309 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1. / self.nTxs) != 0: | |
308 | raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" % ( |
|
310 | raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" % ( | |
309 | 1. / self.nTxs, self.processingHeaderObj.profilesPerBlock) |
|
311 | 1. / self.nTxs, self.processingHeaderObj.profilesPerBlock) | |
310 |
|
312 | |||
311 | if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0: |
|
313 | if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0: | |
312 | raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" % ( |
|
314 | raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" % ( | |
313 | self.nTxs, self.processingHeaderObj.nHeights) |
|
315 | self.nTxs, self.processingHeaderObj.nHeights) | |
314 |
|
316 | |||
315 | self.datablock = self.datablock.reshape( |
|
317 | self.datablock = self.datablock.reshape( | |
316 | (self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock * self.nTxs, self.processingHeaderObj.nHeights / self.nTxs)) |
|
318 | (self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock * self.nTxs, self.processingHeaderObj.nHeights / self.nTxs)) | |
317 |
|
319 | |||
318 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock * self.nTxs |
|
320 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock * self.nTxs | |
319 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights / self.nTxs) * \ |
|
321 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights / self.nTxs) * \ | |
320 | self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight |
|
322 | self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
321 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs |
|
323 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |
322 |
|
324 | |||
323 | return |
|
325 | return | |
324 |
|
326 | |||
325 | def readFirstHeaderFromServer(self): |
|
327 | def readFirstHeaderFromServer(self): | |
326 |
|
328 | |||
327 | self.getFirstHeader() |
|
329 | self.getFirstHeader() | |
328 |
|
330 | |||
329 | self.firstHeaderSize = self.basicHeaderObj.size |
|
331 | self.firstHeaderSize = self.basicHeaderObj.size | |
330 |
|
332 | |||
331 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & |
|
333 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & | |
332 | PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
334 | PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
333 | if datatype == 0: |
|
335 | if datatype == 0: | |
334 | datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
336 | datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
335 | elif datatype == 1: |
|
337 | elif datatype == 1: | |
336 | datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
338 | datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
337 | elif datatype == 2: |
|
339 | elif datatype == 2: | |
338 | datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
340 | datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
339 | elif datatype == 3: |
|
341 | elif datatype == 3: | |
340 | datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
342 | datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
341 | elif datatype == 4: |
|
343 | elif datatype == 4: | |
342 | datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
344 | datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
343 | elif datatype == 5: |
|
345 | elif datatype == 5: | |
344 | datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
346 | datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
345 | else: |
|
347 | else: | |
346 | raise ValueError, 'Data type was not defined' |
|
348 | raise ValueError, 'Data type was not defined' | |
347 |
|
349 | |||
348 | self.dtype = datatype_str |
|
350 | self.dtype = datatype_str | |
349 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
351 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
350 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \ |
|
352 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \ | |
351 | self.firstHeaderSize + self.basicHeaderSize * \ |
|
353 | self.firstHeaderSize + self.basicHeaderSize * \ | |
352 | (self.processingHeaderObj.dataBlocksPerFile - 1) |
|
354 | (self.processingHeaderObj.dataBlocksPerFile - 1) | |
353 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
355 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
354 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
356 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
355 | self.getBlockDimension() |
|
357 | self.getBlockDimension() | |
356 |
|
358 | |||
357 | def getFromServer(self): |
|
359 | def getFromServer(self): | |
358 | self.flagDiscontinuousBlock = 0 |
|
360 | self.flagDiscontinuousBlock = 0 | |
359 | self.profileIndex = 0 |
|
361 | self.profileIndex = 0 | |
360 | self.flagIsNewBlock = 1 |
|
362 | self.flagIsNewBlock = 1 | |
361 | self.dataOut.flagNoData = False |
|
363 | self.dataOut.flagNoData = False | |
362 | self.nTotalBlocks += 1 |
|
364 | self.nTotalBlocks += 1 | |
363 | self.nReadBlocks += 1 |
|
365 | self.nReadBlocks += 1 | |
364 | self.blockPointer = 0 |
|
366 | self.blockPointer = 0 | |
365 |
|
367 | |||
366 | block = self.receiver.recv() |
|
368 | block = self.receiver.recv() | |
367 |
|
369 | |||
368 | self.basicHeaderObj.read(block[self.blockPointer:]) |
|
370 | self.basicHeaderObj.read(block[self.blockPointer:]) | |
369 | self.blockPointer += self.basicHeaderObj.length |
|
371 | self.blockPointer += self.basicHeaderObj.length | |
370 | self.systemHeaderObj.read(block[self.blockPointer:]) |
|
372 | self.systemHeaderObj.read(block[self.blockPointer:]) | |
371 | self.blockPointer += self.systemHeaderObj.length |
|
373 | self.blockPointer += self.systemHeaderObj.length | |
372 | self.radarControllerHeaderObj.read(block[self.blockPointer:]) |
|
374 | self.radarControllerHeaderObj.read(block[self.blockPointer:]) | |
373 | self.blockPointer += self.radarControllerHeaderObj.length |
|
375 | self.blockPointer += self.radarControllerHeaderObj.length | |
374 | self.processingHeaderObj.read(block[self.blockPointer:]) |
|
376 | self.processingHeaderObj.read(block[self.blockPointer:]) | |
375 | self.blockPointer += self.processingHeaderObj.length |
|
377 | self.blockPointer += self.processingHeaderObj.length | |
376 | self.readFirstHeaderFromServer() |
|
378 | self.readFirstHeaderFromServer() | |
377 |
|
379 | |||
378 | timestamp = self.basicHeaderObj.get_datatime() |
|
380 | timestamp = self.basicHeaderObj.get_datatime() | |
379 | print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp) |
|
381 | print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp) | |
380 | current_pointer_location = self.blockPointer |
|
382 | current_pointer_location = self.blockPointer | |
381 | junk = numpy.fromstring( |
|
383 | junk = numpy.fromstring( | |
382 | block[self.blockPointer:], self.dtype, self.blocksize) |
|
384 | block[self.blockPointer:], self.dtype, self.blocksize) | |
383 |
|
385 | |||
384 | try: |
|
386 | try: | |
385 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, |
|
387 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
386 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) |
|
388 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
387 | except: |
|
389 | except: | |
388 | # print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
390 | # print "The read block (%3d) has not enough data" %self.nReadBlocks | |
389 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
391 | if self.waitDataBlock(pointer_location=current_pointer_location): | |
390 | junk = numpy.fromstring( |
|
392 | junk = numpy.fromstring( | |
391 | block[self.blockPointer:], self.dtype, self.blocksize) |
|
393 | block[self.blockPointer:], self.dtype, self.blocksize) | |
392 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, |
|
394 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
393 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) |
|
395 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
394 | # return 0 |
|
396 | # return 0 | |
395 |
|
397 | |||
396 | # Dimensions : nChannels, nProfiles, nSamples |
|
398 | # Dimensions : nChannels, nProfiles, nSamples | |
397 |
|
399 | |||
398 | junk = numpy.transpose(junk, (2, 0, 1)) |
|
400 | junk = numpy.transpose(junk, (2, 0, 1)) | |
399 | self.datablock = junk['real'] + junk['imag'] * 1j |
|
401 | self.datablock = junk['real'] + junk['imag'] * 1j | |
400 | self.profileIndex = 0 |
|
402 | self.profileIndex = 0 | |
401 | if self.selBlocksize == None: |
|
403 | if self.selBlocksize == None: | |
402 | self.selBlocksize = self.dataOut.nProfiles |
|
404 | self.selBlocksize = self.dataOut.nProfiles | |
403 | if self.selBlocktime != None: |
|
405 | if self.selBlocktime != None: | |
404 | if self.dataOut.nCohInt is not None: |
|
406 | if self.dataOut.nCohInt is not None: | |
405 | nCohInt = self.dataOut.nCohInt |
|
407 | nCohInt = self.dataOut.nCohInt | |
406 | else: |
|
408 | else: | |
407 | nCohInt = 1 |
|
409 | nCohInt = 1 | |
408 | self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / ( |
|
410 | self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / ( | |
409 | nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles))) |
|
411 | nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles))) | |
410 | self.dataOut.data = self.datablock[:, |
|
412 | self.dataOut.data = self.datablock[:, | |
411 | self.profileIndex:self.profileIndex + self.selBlocksize, :] |
|
413 | self.profileIndex:self.profileIndex + self.selBlocksize, :] | |
412 | datasize = self.dataOut.data.shape[1] |
|
414 | datasize = self.dataOut.data.shape[1] | |
413 | if datasize < self.selBlocksize: |
|
415 | if datasize < self.selBlocksize: | |
414 | buffer = numpy.zeros( |
|
416 | buffer = numpy.zeros( | |
415 | (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex') |
|
417 | (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex') | |
416 | buffer[:, :datasize, :] = self.dataOut.data |
|
418 | buffer[:, :datasize, :] = self.dataOut.data | |
417 | self.dataOut.data = buffer |
|
419 | self.dataOut.data = buffer | |
418 | self.profileIndex = blockIndex |
|
420 | self.profileIndex = blockIndex | |
419 |
|
421 | |||
420 | self.dataOut.flagDataAsBlock = True |
|
422 | self.dataOut.flagDataAsBlock = True | |
421 | self.flagIsNewBlock = 1 |
|
423 | self.flagIsNewBlock = 1 | |
422 | self.dataOut.realtime = self.online |
|
424 | self.dataOut.realtime = self.online | |
423 |
|
425 | |||
424 | return self.dataOut.data |
|
426 | return self.dataOut.data | |
425 |
|
427 | |||
426 | def getData(self): |
|
428 | def getData(self): | |
427 | """ |
|
429 | """ | |
428 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut |
|
430 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut | |
429 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos |
|
431 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos | |
430 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando |
|
432 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando | |
431 | "readNextBlock" |
|
433 | "readNextBlock" | |
432 |
|
434 | |||
433 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. |
|
435 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. | |
434 |
|
436 | |||
435 | Return: |
|
437 | Return: | |
436 |
|
438 | |||
437 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex |
|
439 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex | |
438 | es igual al total de perfiles leidos desde el archivo. |
|
440 | es igual al total de perfiles leidos desde el archivo. | |
439 |
|
441 | |||
440 | Si self.getByBlock == False: |
|
442 | Si self.getByBlock == False: | |
441 |
|
443 | |||
442 | self.dataOut.data = buffer[:, thisProfile, :] |
|
444 | self.dataOut.data = buffer[:, thisProfile, :] | |
443 |
|
445 | |||
444 | shape = [nChannels, nHeis] |
|
446 | shape = [nChannels, nHeis] | |
445 |
|
447 | |||
446 | Si self.getByBlock == True: |
|
448 | Si self.getByBlock == True: | |
447 |
|
449 | |||
448 | self.dataOut.data = buffer[:, :, :] |
|
450 | self.dataOut.data = buffer[:, :, :] | |
449 |
|
451 | |||
450 | shape = [nChannels, nProfiles, nHeis] |
|
452 | shape = [nChannels, nProfiles, nHeis] | |
451 |
|
453 | |||
452 | Variables afectadas: |
|
454 | Variables afectadas: | |
453 | self.dataOut |
|
455 | self.dataOut | |
454 | self.profileIndex |
|
456 | self.profileIndex | |
455 |
|
457 | |||
456 | Affected: |
|
458 | Affected: | |
457 | self.dataOut |
|
459 | self.dataOut | |
458 | self.profileIndex |
|
460 | self.profileIndex | |
459 | self.flagDiscontinuousBlock |
|
461 | self.flagDiscontinuousBlock | |
460 | self.flagIsNewBlock |
|
462 | self.flagIsNewBlock | |
461 | """ |
|
463 | """ | |
462 | if self.flagNoMoreFiles: |
|
464 | if self.flagNoMoreFiles: | |
463 | self.dataOut.flagNoData = True |
|
465 | self.dataOut.flagNoData = True | |
464 | print 'Process finished' |
|
466 | print 'Process finished' | |
465 | return 0 |
|
467 | return 0 | |
466 | self.flagDiscontinuousBlock = 0 |
|
468 | self.flagDiscontinuousBlock = 0 | |
467 | self.flagIsNewBlock = 0 |
|
469 | self.flagIsNewBlock = 0 | |
468 | if self.__hasNotDataInBuffer(): |
|
470 | if self.__hasNotDataInBuffer(): | |
469 | if not(self.readNextBlock()): |
|
471 | if not(self.readNextBlock()): | |
470 | return 0 |
|
472 | return 0 | |
471 |
|
473 | |||
472 | self.getFirstHeader() |
|
474 | self.getFirstHeader() | |
473 |
|
475 | |||
474 | self.reshapeData() |
|
476 | self.reshapeData() | |
475 | if self.datablock is None: |
|
477 | if self.datablock is None: | |
476 | self.dataOut.flagNoData = True |
|
478 | self.dataOut.flagNoData = True | |
477 | return 0 |
|
479 | return 0 | |
478 |
|
480 | |||
479 | if not self.getByBlock: |
|
481 | if not self.getByBlock: | |
480 |
|
482 | |||
481 | """ |
|
483 | """ | |
482 | Return profile by profile |
|
484 | Return profile by profile | |
483 |
|
485 | |||
484 | If nTxs > 1 then one profile is divided by nTxs and number of total |
|
486 | If nTxs > 1 then one profile is divided by nTxs and number of total | |
485 | blocks is increased by nTxs (nProfiles *= nTxs) |
|
487 | blocks is increased by nTxs (nProfiles *= nTxs) | |
486 | """ |
|
488 | """ | |
487 | self.dataOut.flagDataAsBlock = False |
|
489 | self.dataOut.flagDataAsBlock = False | |
488 | self.dataOut.data = self.datablock[:, self.profileIndex, :] |
|
490 | self.dataOut.data = self.datablock[:, self.profileIndex, :] | |
489 | self.dataOut.profileIndex = self.profileIndex |
|
491 | self.dataOut.profileIndex = self.profileIndex | |
490 |
|
492 | |||
491 | self.profileIndex += 1 |
|
493 | self.profileIndex += 1 | |
492 |
|
494 | |||
493 | # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles: |
|
495 | # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles: | |
494 | # """ |
|
496 | # """ | |
495 | # Return all block |
|
497 | # Return all block | |
496 | # """ |
|
498 | # """ | |
497 | # self.dataOut.flagDataAsBlock = True |
|
499 | # self.dataOut.flagDataAsBlock = True | |
498 | # self.dataOut.data = self.datablock |
|
500 | # self.dataOut.data = self.datablock | |
499 | # self.dataOut.profileIndex = self.dataOut.nProfiles - 1 |
|
501 | # self.dataOut.profileIndex = self.dataOut.nProfiles - 1 | |
500 | # |
|
502 | # | |
501 | # self.profileIndex = self.dataOut.nProfiles |
|
503 | # self.profileIndex = self.dataOut.nProfiles | |
502 |
|
504 | |||
503 | else: |
|
505 | else: | |
504 | """ |
|
506 | """ | |
505 | Return a block |
|
507 | Return a block | |
506 | """ |
|
508 | """ | |
507 | if self.selBlocksize == None: |
|
509 | if self.selBlocksize == None: | |
508 | self.selBlocksize = self.dataOut.nProfiles |
|
510 | self.selBlocksize = self.dataOut.nProfiles | |
509 | if self.selBlocktime != None: |
|
511 | if self.selBlocktime != None: | |
510 | if self.dataOut.nCohInt is not None: |
|
512 | if self.dataOut.nCohInt is not None: | |
511 | nCohInt = self.dataOut.nCohInt |
|
513 | nCohInt = self.dataOut.nCohInt | |
512 | else: |
|
514 | else: | |
513 | nCohInt = 1 |
|
515 | nCohInt = 1 | |
514 | self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / ( |
|
516 | self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / ( | |
515 | nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles))) |
|
517 | nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles))) | |
516 |
|
518 | |||
517 | self.dataOut.data = self.datablock[:, |
|
519 | self.dataOut.data = self.datablock[:, | |
518 | self.profileIndex:self.profileIndex + self.selBlocksize, :] |
|
520 | self.profileIndex:self.profileIndex + self.selBlocksize, :] | |
519 | self.profileIndex += self.selBlocksize |
|
521 | self.profileIndex += self.selBlocksize | |
520 | datasize = self.dataOut.data.shape[1] |
|
522 | datasize = self.dataOut.data.shape[1] | |
521 |
|
523 | |||
522 | if datasize < self.selBlocksize: |
|
524 | if datasize < self.selBlocksize: | |
523 | buffer = numpy.zeros( |
|
525 | buffer = numpy.zeros( | |
524 | (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex') |
|
526 | (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex') | |
525 | buffer[:, :datasize, :] = self.dataOut.data |
|
527 | buffer[:, :datasize, :] = self.dataOut.data | |
526 |
|
528 | |||
527 | while datasize < self.selBlocksize: # Not enough profiles to fill the block |
|
529 | while datasize < self.selBlocksize: # Not enough profiles to fill the block | |
528 | if not(self.readNextBlock()): |
|
530 | if not(self.readNextBlock()): | |
529 | return 0 |
|
531 | return 0 | |
530 | self.getFirstHeader() |
|
532 | self.getFirstHeader() | |
531 | self.reshapeData() |
|
533 | self.reshapeData() | |
532 | if self.datablock is None: |
|
534 | if self.datablock is None: | |
533 | self.dataOut.flagNoData = True |
|
535 | self.dataOut.flagNoData = True | |
534 | return 0 |
|
536 | return 0 | |
535 | # stack data |
|
537 | # stack data | |
536 | blockIndex = self.selBlocksize - datasize |
|
538 | blockIndex = self.selBlocksize - datasize | |
537 | datablock1 = self.datablock[:, :blockIndex, :] |
|
539 | datablock1 = self.datablock[:, :blockIndex, :] | |
538 |
|
540 | |||
539 | buffer[:, datasize:datasize + |
|
541 | buffer[:, datasize:datasize + | |
540 | datablock1.shape[1], :] = datablock1 |
|
542 | datablock1.shape[1], :] = datablock1 | |
541 | datasize += datablock1.shape[1] |
|
543 | datasize += datablock1.shape[1] | |
542 |
|
544 | |||
543 | self.dataOut.data = buffer |
|
545 | self.dataOut.data = buffer | |
544 | self.profileIndex = blockIndex |
|
546 | self.profileIndex = blockIndex | |
545 |
|
547 | |||
546 | self.dataOut.flagDataAsBlock = True |
|
548 | self.dataOut.flagDataAsBlock = True | |
547 | self.dataOut.nProfiles = self.dataOut.data.shape[1] |
|
549 | self.dataOut.nProfiles = self.dataOut.data.shape[1] | |
548 |
|
550 | |||
549 | self.dataOut.flagNoData = False |
|
551 | self.dataOut.flagNoData = False | |
550 |
|
552 | |||
551 | self.getBasicHeader() |
|
553 | self.getBasicHeader() | |
552 |
|
554 | |||
553 | self.dataOut.realtime = self.online |
|
555 | self.dataOut.realtime = self.online | |
554 |
|
556 | |||
555 | return self.dataOut.data |
|
557 | return self.dataOut.data | |
556 |
|
558 | |||
557 |
|
559 | |||
558 | class VoltageWriter(JRODataWriter, Operation): |
|
560 | class VoltageWriter(JRODataWriter, Operation): | |
559 | """ |
|
561 | """ | |
560 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
562 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
561 | de los datos siempre se realiza por bloques. |
|
563 | de los datos siempre se realiza por bloques. | |
562 | """ |
|
564 | """ | |
563 |
|
565 | |||
564 | ext = ".r" |
|
566 | ext = ".r" | |
565 |
|
567 | |||
566 | optchar = "D" |
|
568 | optchar = "D" | |
567 |
|
569 | |||
568 | shapeBuffer = None |
|
570 | shapeBuffer = None | |
569 |
|
571 | |||
570 | def __init__(self, **kwargs): |
|
572 | def __init__(self, **kwargs): | |
571 | """ |
|
573 | """ | |
572 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
574 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
573 |
|
575 | |||
574 | Affected: |
|
576 | Affected: | |
575 | self.dataOut |
|
577 | self.dataOut | |
576 |
|
578 | |||
577 | Return: None |
|
579 | Return: None | |
578 | """ |
|
580 | """ | |
579 | Operation.__init__(self, **kwargs) |
|
581 | Operation.__init__(self, **kwargs) | |
580 |
|
582 | |||
581 | self.nTotalBlocks = 0 |
|
583 | self.nTotalBlocks = 0 | |
582 |
|
584 | |||
583 | self.profileIndex = 0 |
|
585 | self.profileIndex = 0 | |
584 |
|
586 | |||
585 | self.isConfig = False |
|
587 | self.isConfig = False | |
586 |
|
588 | |||
587 | self.fp = None |
|
589 | self.fp = None | |
588 |
|
590 | |||
589 | self.flagIsNewFile = 1 |
|
591 | self.flagIsNewFile = 1 | |
590 |
|
592 | |||
591 | self.blockIndex = 0 |
|
593 | self.blockIndex = 0 | |
592 |
|
594 | |||
593 | self.flagIsNewBlock = 0 |
|
595 | self.flagIsNewBlock = 0 | |
594 |
|
596 | |||
595 | self.setFile = None |
|
597 | self.setFile = None | |
596 |
|
598 | |||
597 | self.dtype = None |
|
599 | self.dtype = None | |
598 |
|
600 | |||
599 | self.path = None |
|
601 | self.path = None | |
600 |
|
602 | |||
601 | self.filename = None |
|
603 | self.filename = None | |
602 |
|
604 | |||
603 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
605 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
604 |
|
606 | |||
605 | self.systemHeaderObj = SystemHeader() |
|
607 | self.systemHeaderObj = SystemHeader() | |
606 |
|
608 | |||
607 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
609 | self.radarControllerHeaderObj = RadarControllerHeader() | |
608 |
|
610 | |||
609 | self.processingHeaderObj = ProcessingHeader() |
|
611 | self.processingHeaderObj = ProcessingHeader() | |
610 |
|
612 | |||
611 | def hasAllDataInBuffer(self): |
|
613 | def hasAllDataInBuffer(self): | |
612 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
614 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
613 | return 1 |
|
615 | return 1 | |
614 | return 0 |
|
616 | return 0 | |
615 |
|
617 | |||
616 | def setBlockDimension(self): |
|
618 | def setBlockDimension(self): | |
617 | """ |
|
619 | """ | |
618 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
620 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
619 |
|
621 | |||
620 | Affected: |
|
622 | Affected: | |
621 | self.shape_spc_Buffer |
|
623 | self.shape_spc_Buffer | |
622 | self.shape_cspc_Buffer |
|
624 | self.shape_cspc_Buffer | |
623 | self.shape_dc_Buffer |
|
625 | self.shape_dc_Buffer | |
624 |
|
626 | |||
625 | Return: None |
|
627 | Return: None | |
626 | """ |
|
628 | """ | |
627 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
629 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
628 | self.processingHeaderObj.nHeights, |
|
630 | self.processingHeaderObj.nHeights, | |
629 | self.systemHeaderObj.nChannels) |
|
631 | self.systemHeaderObj.nChannels) | |
630 |
|
632 | |||
631 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
633 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
632 | self.processingHeaderObj.profilesPerBlock, |
|
634 | self.processingHeaderObj.profilesPerBlock, | |
633 | self.processingHeaderObj.nHeights), |
|
635 | self.processingHeaderObj.nHeights), | |
634 | dtype=numpy.dtype('complex64')) |
|
636 | dtype=numpy.dtype('complex64')) | |
635 |
|
637 | |||
636 | def writeBlock(self): |
|
638 | def writeBlock(self): | |
637 | """ |
|
639 | """ | |
638 | Escribe el buffer en el file designado |
|
640 | Escribe el buffer en el file designado | |
639 |
|
641 | |||
640 | Affected: |
|
642 | Affected: | |
641 | self.profileIndex |
|
643 | self.profileIndex | |
642 | self.flagIsNewFile |
|
644 | self.flagIsNewFile | |
643 | self.flagIsNewBlock |
|
645 | self.flagIsNewBlock | |
644 | self.nTotalBlocks |
|
646 | self.nTotalBlocks | |
645 | self.blockIndex |
|
647 | self.blockIndex | |
646 |
|
648 | |||
647 | Return: None |
|
649 | Return: None | |
648 | """ |
|
650 | """ | |
649 | data = numpy.zeros(self.shapeBuffer, self.dtype) |
|
651 | data = numpy.zeros(self.shapeBuffer, self.dtype) | |
650 |
|
652 | |||
651 | junk = numpy.transpose(self.datablock, (1, 2, 0)) |
|
653 | junk = numpy.transpose(self.datablock, (1, 2, 0)) | |
652 |
|
654 | |||
653 | data['real'] = junk.real |
|
655 | data['real'] = junk.real | |
654 | data['imag'] = junk.imag |
|
656 | data['imag'] = junk.imag | |
655 |
|
657 | |||
656 | data = data.reshape((-1)) |
|
658 | data = data.reshape((-1)) | |
657 |
|
659 | |||
658 | data.tofile(self.fp) |
|
660 | data.tofile(self.fp) | |
659 |
|
661 | |||
660 | self.datablock.fill(0) |
|
662 | self.datablock.fill(0) | |
661 |
|
663 | |||
662 | self.profileIndex = 0 |
|
664 | self.profileIndex = 0 | |
663 | self.flagIsNewFile = 0 |
|
665 | self.flagIsNewFile = 0 | |
664 | self.flagIsNewBlock = 1 |
|
666 | self.flagIsNewBlock = 1 | |
665 |
|
667 | |||
666 | self.blockIndex += 1 |
|
668 | self.blockIndex += 1 | |
667 | self.nTotalBlocks += 1 |
|
669 | self.nTotalBlocks += 1 | |
668 |
|
670 | |||
669 | # print "[Writing] Block = %04d" %self.blockIndex |
|
671 | # print "[Writing] Block = %04d" %self.blockIndex | |
670 |
|
672 | |||
671 | def putData(self): |
|
673 | def putData(self): | |
672 | """ |
|
674 | """ | |
673 | Setea un bloque de datos y luego los escribe en un file |
|
675 | Setea un bloque de datos y luego los escribe en un file | |
674 |
|
676 | |||
675 | Affected: |
|
677 | Affected: | |
676 | self.flagIsNewBlock |
|
678 | self.flagIsNewBlock | |
677 | self.profileIndex |
|
679 | self.profileIndex | |
678 |
|
680 | |||
679 | Return: |
|
681 | Return: | |
680 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
682 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
681 | 1 : Si se escribio la data de un bloque en un file |
|
683 | 1 : Si se escribio la data de un bloque en un file | |
682 | """ |
|
684 | """ | |
683 | if self.dataOut.flagNoData: |
|
685 | if self.dataOut.flagNoData: | |
684 | return 0 |
|
686 | return 0 | |
685 |
|
687 | |||
686 | self.flagIsNewBlock = 0 |
|
688 | self.flagIsNewBlock = 0 | |
687 |
|
689 | |||
688 | if self.dataOut.flagDiscontinuousBlock: |
|
690 | if self.dataOut.flagDiscontinuousBlock: | |
689 | self.datablock.fill(0) |
|
691 | self.datablock.fill(0) | |
690 | self.profileIndex = 0 |
|
692 | self.profileIndex = 0 | |
691 | self.setNextFile() |
|
693 | self.setNextFile() | |
692 |
|
694 | |||
693 | if self.profileIndex == 0: |
|
695 | if self.profileIndex == 0: | |
694 | self.setBasicHeader() |
|
696 | self.setBasicHeader() | |
695 |
|
697 | |||
696 | self.datablock[:, self.profileIndex, :] = self.dataOut.data |
|
698 | self.datablock[:, self.profileIndex, :] = self.dataOut.data | |
697 |
|
699 | |||
698 | self.profileIndex += 1 |
|
700 | self.profileIndex += 1 | |
699 |
|
701 | |||
700 | if self.hasAllDataInBuffer(): |
|
702 | if self.hasAllDataInBuffer(): | |
701 | # if self.flagIsNewFile: |
|
703 | # if self.flagIsNewFile: | |
702 | self.writeNextBlock() |
|
704 | self.writeNextBlock() | |
703 | # self.setFirstHeader() |
|
705 | # self.setFirstHeader() | |
704 |
|
706 | |||
705 | return 1 |
|
707 | return 1 | |
706 |
|
708 | |||
707 | def __getBlockSize(self): |
|
709 | def __getBlockSize(self): | |
708 | ''' |
|
710 | ''' | |
709 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
711 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
710 | ''' |
|
712 | ''' | |
711 |
|
713 | |||
712 | dtype_width = self.getDtypeWidth() |
|
714 | dtype_width = self.getDtypeWidth() | |
713 |
|
715 | |||
714 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * |
|
716 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * | |
715 | self.profilesPerBlock * dtype_width * 2) |
|
717 | self.profilesPerBlock * dtype_width * 2) | |
716 |
|
718 | |||
717 | return blocksize |
|
719 | return blocksize | |
718 |
|
720 | |||
719 | def setFirstHeader(self): |
|
721 | def setFirstHeader(self): | |
720 | """ |
|
722 | """ | |
721 | Obtiene una copia del First Header |
|
723 | Obtiene una copia del First Header | |
722 |
|
724 | |||
723 | Affected: |
|
725 | Affected: | |
724 | self.systemHeaderObj |
|
726 | self.systemHeaderObj | |
725 | self.radarControllerHeaderObj |
|
727 | self.radarControllerHeaderObj | |
726 | self.dtype |
|
728 | self.dtype | |
727 |
|
729 | |||
728 | Return: |
|
730 | Return: | |
729 | None |
|
731 | None | |
730 | """ |
|
732 | """ | |
731 |
|
733 | |||
732 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
734 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
733 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
735 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
734 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
736 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
735 |
|
737 | |||
736 | self.processingHeaderObj.dtype = 0 # Voltage |
|
738 | self.processingHeaderObj.dtype = 0 # Voltage | |
737 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
739 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
738 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
740 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
739 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
741 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
740 | # podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
742 | # podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
741 | self.processingHeaderObj.nWindows = 1 |
|
743 | self.processingHeaderObj.nWindows = 1 | |
742 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
744 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
743 | # Cuando la data de origen es de tipo Voltage |
|
745 | # Cuando la data de origen es de tipo Voltage | |
744 | self.processingHeaderObj.nIncohInt = 1 |
|
746 | self.processingHeaderObj.nIncohInt = 1 | |
745 | # Cuando la data de origen es de tipo Voltage |
|
747 | # Cuando la data de origen es de tipo Voltage | |
746 | self.processingHeaderObj.totalSpectra = 0 |
|
748 | self.processingHeaderObj.totalSpectra = 0 | |
747 |
|
749 | |||
748 | if self.dataOut.code is not None: |
|
750 | if self.dataOut.code is not None: | |
749 | self.processingHeaderObj.code = self.dataOut.code |
|
751 | self.processingHeaderObj.code = self.dataOut.code | |
750 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
752 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
751 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
753 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
752 |
|
754 | |||
753 | if self.processingHeaderObj.nWindows != 0: |
|
755 | if self.processingHeaderObj.nWindows != 0: | |
754 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
756 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
755 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - \ |
|
757 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - \ | |
756 | self.dataOut.heightList[0] |
|
758 | self.dataOut.heightList[0] | |
757 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
759 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
758 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
760 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
759 |
|
761 | |||
760 | self.processingHeaderObj.processFlags = self.getProcessFlags() |
|
762 | self.processingHeaderObj.processFlags = self.getProcessFlags() | |
761 |
|
763 | |||
762 | self.setBasicHeader() |
|
764 | self.setBasicHeader() |
General Comments 0
You need to be logged in to leave comments.
Login now