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