##// END OF EJS Templates
agregado metodos a header class
Jose Chavez -
r980:ea5ace19bd59
parent child
Show More
@@ -1,851 +1,861
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10 import inspect
10
11
11 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 3e8
13 SPEED_OF_LIGHT = 3e8
13
14
14 BASIC_STRUCTURE = numpy.dtype([
15 BASIC_STRUCTURE = numpy.dtype([
15 ('nSize','<u4'),
16 ('nSize','<u4'),
16 ('nVersion','<u2'),
17 ('nVersion','<u2'),
17 ('nDataBlockId','<u4'),
18 ('nDataBlockId','<u4'),
18 ('nUtime','<u4'),
19 ('nUtime','<u4'),
19 ('nMilsec','<u2'),
20 ('nMilsec','<u2'),
20 ('nTimezone','<i2'),
21 ('nTimezone','<i2'),
21 ('nDstflag','<i2'),
22 ('nDstflag','<i2'),
22 ('nErrorCount','<u4')
23 ('nErrorCount','<u4')
23 ])
24 ])
24
25
25 SYSTEM_STRUCTURE = numpy.dtype([
26 SYSTEM_STRUCTURE = numpy.dtype([
26 ('nSize','<u4'),
27 ('nSize','<u4'),
27 ('nNumSamples','<u4'),
28 ('nNumSamples','<u4'),
28 ('nNumProfiles','<u4'),
29 ('nNumProfiles','<u4'),
29 ('nNumChannels','<u4'),
30 ('nNumChannels','<u4'),
30 ('nADCResolution','<u4'),
31 ('nADCResolution','<u4'),
31 ('nPCDIOBusWidth','<u4'),
32 ('nPCDIOBusWidth','<u4'),
32 ])
33 ])
33
34
34 RADAR_STRUCTURE = numpy.dtype([
35 RADAR_STRUCTURE = numpy.dtype([
35 ('nSize','<u4'),
36 ('nSize','<u4'),
36 ('nExpType','<u4'),
37 ('nExpType','<u4'),
37 ('nNTx','<u4'),
38 ('nNTx','<u4'),
38 ('fIpp','<f4'),
39 ('fIpp','<f4'),
39 ('fTxA','<f4'),
40 ('fTxA','<f4'),
40 ('fTxB','<f4'),
41 ('fTxB','<f4'),
41 ('nNumWindows','<u4'),
42 ('nNumWindows','<u4'),
42 ('nNumTaus','<u4'),
43 ('nNumTaus','<u4'),
43 ('nCodeType','<u4'),
44 ('nCodeType','<u4'),
44 ('nLine6Function','<u4'),
45 ('nLine6Function','<u4'),
45 ('nLine5Function','<u4'),
46 ('nLine5Function','<u4'),
46 ('fClock','<f4'),
47 ('fClock','<f4'),
47 ('nPrePulseBefore','<u4'),
48 ('nPrePulseBefore','<u4'),
48 ('nPrePulseAfter','<u4'),
49 ('nPrePulseAfter','<u4'),
49 ('sRangeIPP','<a20'),
50 ('sRangeIPP','<a20'),
50 ('sRangeTxA','<a20'),
51 ('sRangeTxA','<a20'),
51 ('sRangeTxB','<a20'),
52 ('sRangeTxB','<a20'),
52 ])
53 ])
53
54
54 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
55 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
55
56
56
57
57 PROCESSING_STRUCTURE = numpy.dtype([
58 PROCESSING_STRUCTURE = numpy.dtype([
58 ('nSize','<u4'),
59 ('nSize','<u4'),
59 ('nDataType','<u4'),
60 ('nDataType','<u4'),
60 ('nSizeOfDataBlock','<u4'),
61 ('nSizeOfDataBlock','<u4'),
61 ('nProfilesperBlock','<u4'),
62 ('nProfilesperBlock','<u4'),
62 ('nDataBlocksperFile','<u4'),
63 ('nDataBlocksperFile','<u4'),
63 ('nNumWindows','<u4'),
64 ('nNumWindows','<u4'),
64 ('nProcessFlags','<u4'),
65 ('nProcessFlags','<u4'),
65 ('nCoherentIntegrations','<u4'),
66 ('nCoherentIntegrations','<u4'),
66 ('nIncoherentIntegrations','<u4'),
67 ('nIncoherentIntegrations','<u4'),
67 ('nTotalSpectra','<u4')
68 ('nTotalSpectra','<u4')
68 ])
69 ])
69
70
70 class Header(object):
71 class Header(object):
71
72
72 def __init__(self):
73 def __init__(self):
73 raise NotImplementedError
74 raise NotImplementedError
74
75
75 def copy(self):
76 def copy(self):
76 return copy.deepcopy(self)
77 return copy.deepcopy(self)
77
78
78 def read(self):
79 def read(self):
79
80
80 raise NotImplementedError
81 raise NotImplementedError
81
82
82 def write(self):
83 def write(self):
83
84
84 raise NotImplementedError
85 raise NotImplementedError
86
87 def getAllowedArgs(self):
88 return inspect.getargspec(self.__init__).args
85
89
86 def printInfo(self):
90 def printInfo(self):
87
91
88 message = "#"*50 + "\n"
92 message = "#"*50 + "\n"
89 message += self.__class__.__name__.upper() + "\n"
93 message += self.__class__.__name__.upper() + "\n"
90 message += "#"*50 + "\n"
94 message += "#"*50 + "\n"
91
95
92 keyList = self.__dict__.keys()
96 keyList = self.__dict__.keys()
93 keyList.sort()
97 keyList.sort()
94
98
95 for key in keyList:
99 for key in keyList:
96 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
100 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
97
101
98 if "size" not in keyList:
102 if "size" not in keyList:
99 attr = getattr(self, "size")
103 attr = getattr(self, "size")
100
104
101 if attr:
105 if attr:
102 message += "%s = %s" %("size", attr) + "\n"
106 message += "%s = %s" %("size", attr) + "\n"
103
107
104 print message
108 print message
105
109
106 class BasicHeader(Header):
110 class BasicHeader(Header):
107
111
108 size = None
112 size = None
109 version = None
113 version = None
110 dataBlock = None
114 dataBlock = None
111 utc = None
115 utc = None
112 ltc = None
116 ltc = None
113 miliSecond = None
117 miliSecond = None
114 timeZone = None
118 timeZone = None
115 dstFlag = None
119 dstFlag = None
116 errorCount = None
120 errorCount = None
117 datatime = None
121 datatime = None
122 structure = BASIC_STRUCTURE
118 __LOCALTIME = None
123 __LOCALTIME = None
119
124
120 def __init__(self, useLocalTime=True):
125 def __init__(self, useLocalTime=True):
121
126
122 self.size = 24
127 self.size = 24
123 self.version = 0
128 self.version = 0
124 self.dataBlock = 0
129 self.dataBlock = 0
125 self.utc = 0
130 self.utc = 0
126 self.miliSecond = 0
131 self.miliSecond = 0
127 self.timeZone = 0
132 self.timeZone = 0
128 self.dstFlag = 0
133 self.dstFlag = 0
129 self.errorCount = 0
134 self.errorCount = 0
130
135
131 self.useLocalTime = useLocalTime
136 self.useLocalTime = useLocalTime
132
137
133 def read(self, fp):
138 def read(self, fp):
134
139
135 self.length = 0
140 self.length = 0
136 try:
141 try:
137 if hasattr(fp, 'read'):
142 if hasattr(fp, 'read'):
138 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
143 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
139 else:
144 else:
140 header = numpy.fromstring(fp, BASIC_STRUCTURE,1)
145 header = numpy.fromstring(fp, BASIC_STRUCTURE,1)
141 except Exception, e:
146 except Exception, e:
142 print "BasicHeader: "
147 print "BasicHeader: "
143 print e
148 print e
144 return 0
149 return 0
145
150
146 self.size = int(header['nSize'][0])
151 self.size = int(header['nSize'][0])
147 self.version = int(header['nVersion'][0])
152 self.version = int(header['nVersion'][0])
148 self.dataBlock = int(header['nDataBlockId'][0])
153 self.dataBlock = int(header['nDataBlockId'][0])
149 self.utc = int(header['nUtime'][0])
154 self.utc = int(header['nUtime'][0])
150 self.miliSecond = int(header['nMilsec'][0])
155 self.miliSecond = int(header['nMilsec'][0])
151 self.timeZone = int(header['nTimezone'][0])
156 self.timeZone = int(header['nTimezone'][0])
152 self.dstFlag = int(header['nDstflag'][0])
157 self.dstFlag = int(header['nDstflag'][0])
153 self.errorCount = int(header['nErrorCount'][0])
158 self.errorCount = int(header['nErrorCount'][0])
154
159
155 if self.size < 24:
160 if self.size < 24:
156 return 0
161 return 0
157
162
158 self.length = header.nbytes
163 self.length = header.nbytes
159 return 1
164 return 1
160
165
161 def write(self, fp):
166 def write(self, fp):
162
167
163 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
168 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
164 header = numpy.array(headerTuple, BASIC_STRUCTURE)
169 header = numpy.array(headerTuple, BASIC_STRUCTURE)
165 header.tofile(fp)
170 header.tofile(fp)
166
171
167 return 1
172 return 1
168
173
169 def get_ltc(self):
174 def get_ltc(self):
170
175
171 return self.utc - self.timeZone*60
176 return self.utc - self.timeZone*60
172
177
173 def set_ltc(self, value):
178 def set_ltc(self, value):
174
179
175 self.utc = value + self.timeZone*60
180 self.utc = value + self.timeZone*60
176
181
177 def get_datatime(self):
182 def get_datatime(self):
178
183
179 return datetime.datetime.utcfromtimestamp(self.ltc)
184 return datetime.datetime.utcfromtimestamp(self.ltc)
180
185
181 ltc = property(get_ltc, set_ltc)
186 ltc = property(get_ltc, set_ltc)
182 datatime = property(get_datatime)
187 datatime = property(get_datatime)
183
188
184 class SystemHeader(Header):
189 class SystemHeader(Header):
185
190
186 size = None
191 size = None
187 nSamples = None
192 nSamples = None
188 nProfiles = None
193 nProfiles = None
189 nChannels = None
194 nChannels = None
190 adcResolution = None
195 adcResolution = None
191 pciDioBusWidth = None
196 pciDioBusWidth = None
192
197 structure = SYSTEM_STRUCTURE
198
193 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
199 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
194
200
195 self.size = 24
201 self.size = 24
196 self.nSamples = nSamples
202 self.nSamples = nSamples
197 self.nProfiles = nProfiles
203 self.nProfiles = nProfiles
198 self.nChannels = nChannels
204 self.nChannels = nChannels
199 self.adcResolution = adcResolution
205 self.adcResolution = adcResolution
200 self.pciDioBusWidth = pciDioBusWith
206 self.pciDioBusWidth = pciDioBusWith
201
207
202 def read(self, fp):
208 def read(self, fp):
203 self.length = 0
209 self.length = 0
204 try:
210 try:
205 startFp = fp.tell()
211 startFp = fp.tell()
206 except Exception, e:
212 except Exception, e:
207 startFp = None
213 startFp = None
208 pass
214 pass
209
215
210 try:
216 try:
211 if hasattr(fp, 'read'):
217 if hasattr(fp, 'read'):
212 header = numpy.fromfile(fp, SYSTEM_STRUCTURE,1)
218 header = numpy.fromfile(fp, SYSTEM_STRUCTURE,1)
213 else:
219 else:
214 header = numpy.fromstring(fp, SYSTEM_STRUCTURE,1)
220 header = numpy.fromstring(fp, SYSTEM_STRUCTURE,1)
215 except Exception, e:
221 except Exception, e:
216 print "System Header: " + str(e)
222 print "System Header: " + str(e)
217 return 0
223 return 0
218
224
219 self.size = header['nSize'][0]
225 self.size = header['nSize'][0]
220 self.nSamples = header['nNumSamples'][0]
226 self.nSamples = header['nNumSamples'][0]
221 self.nProfiles = header['nNumProfiles'][0]
227 self.nProfiles = header['nNumProfiles'][0]
222 self.nChannels = header['nNumChannels'][0]
228 self.nChannels = header['nNumChannels'][0]
223 self.adcResolution = header['nADCResolution'][0]
229 self.adcResolution = header['nADCResolution'][0]
224 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
230 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
225
231
226
232
227 if startFp is not None:
233 if startFp is not None:
228 endFp = self.size + startFp
234 endFp = self.size + startFp
229
235
230 if fp.tell() > endFp:
236 if fp.tell() > endFp:
231 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
237 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
232 return 0
238 return 0
233
239
234 if fp.tell() < endFp:
240 if fp.tell() < endFp:
235 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
241 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
236 return 0
242 return 0
237
243
238 self.length = header.nbytes
244 self.length = header.nbytes
239 return 1
245 return 1
240
246
241 def write(self, fp):
247 def write(self, fp):
242
248
243 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
249 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
244 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
250 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
245 header.tofile(fp)
251 header.tofile(fp)
246
252
247 return 1
253 return 1
248
254
249 class RadarControllerHeader(Header):
255 class RadarControllerHeader(Header):
250
256
251 expType = None
257 expType = None
252 nTx = None
258 nTx = None
253 ipp = None
259 ipp = None
254 txA = None
260 txA = None
255 txB = None
261 txB = None
256 nWindows = None
262 nWindows = None
257 numTaus = None
263 numTaus = None
258 codeType = None
264 codeType = None
259 line6Function = None
265 line6Function = None
260 line5Function = None
266 line5Function = None
261 fClock = None
267 fClock = None
262 prePulseBefore = None
268 prePulseBefore = None
263 prePulserAfter = None
269 prePulserAfter = None
264 rangeIpp = None
270 rangeIpp = None
265 rangeTxA = None
271 rangeTxA = None
266 rangeTxB = None
272 rangeTxB = None
267
273 structure = RADAR_STRUCTURE
268 __size = None
274 __size = None
269
275
270 def __init__(self, expType=2, nTx=1,
276 def __init__(self, expType=2, nTx=1,
271 ippKm=None, txA=0, txB=0,
277 ippKm=None, txA=0, txB=0,
272 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
278 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
273 numTaus=0, line6Function=0, line5Function=0, fClock=None,
279 numTaus=0, line6Function=0, line5Function=0, fClock=None,
274 prePulseBefore=0, prePulseAfter=0,
280 prePulseBefore=0, prePulseAfter=0,
275 codeType=0, nCode=0, nBaud=0, code=None,
281 codeType=0, nCode=0, nBaud=0, code=None,
276 flip1=0, flip2=0):
282 flip1=0, flip2=0):
277
283
278 # self.size = 116
284 # self.size = 116
279 self.expType = expType
285 self.expType = expType
280 self.nTx = nTx
286 self.nTx = nTx
281 self.ipp = ippKm
287 self.ipp = ippKm
282 self.txA = txA
288 self.txA = txA
283 self.txB = txB
289 self.txB = txB
284 self.rangeIpp = ippKm
290 self.rangeIpp = ippKm
285 self.rangeTxA = txA
291 self.rangeTxA = txA
286 self.rangeTxB = txB
292 self.rangeTxB = txB
287
293
288 self.nWindows = nWindows
294 self.nWindows = nWindows
289 self.numTaus = numTaus
295 self.numTaus = numTaus
290 self.codeType = codeType
296 self.codeType = codeType
291 self.line6Function = line6Function
297 self.line6Function = line6Function
292 self.line5Function = line5Function
298 self.line5Function = line5Function
293 self.fClock = fClock
299 self.fClock = fClock
294 self.prePulseBefore = prePulseBefore
300 self.prePulseBefore = prePulseBefore
295 self.prePulserAfter = prePulseAfter
301 self.prePulserAfter = prePulseAfter
296
302
297 self.nHeights = nHeights
303 self.nHeights = nHeights
298 self.firstHeight = firstHeight
304 self.firstHeight = firstHeight
299 self.deltaHeight = deltaHeight
305 self.deltaHeight = deltaHeight
300 self.samplesWin = nHeights
306 self.samplesWin = nHeights
301
307
302 self.nCode = nCode
308 self.nCode = nCode
303 self.nBaud = nBaud
309 self.nBaud = nBaud
304 self.code = code
310 self.code = code
305 self.flip1 = flip1
311 self.flip1 = flip1
306 self.flip2 = flip2
312 self.flip2 = flip2
307
313
308 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
314 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
309 # self.dynamic = numpy.array([],numpy.dtype('byte'))
315 # self.dynamic = numpy.array([],numpy.dtype('byte'))
310
316
311 if self.fClock is None and self.deltaHeight is not None:
317 if self.fClock is None and self.deltaHeight is not None:
312 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
318 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
313
319
314 def read(self, fp):
320 def read(self, fp):
315 self.length = 0
321 self.length = 0
316 try:
322 try:
317 startFp = fp.tell()
323 startFp = fp.tell()
318 except Exception, e:
324 except Exception, e:
319 startFp = None
325 startFp = None
320 pass
326 pass
321
327
322 try:
328 try:
323 if hasattr(fp, 'read'):
329 if hasattr(fp, 'read'):
324 header = numpy.fromfile(fp, RADAR_STRUCTURE,1)
330 header = numpy.fromfile(fp, RADAR_STRUCTURE,1)
325 else:
331 else:
326 header = numpy.fromstring(fp, RADAR_STRUCTURE,1)
332 header = numpy.fromstring(fp, RADAR_STRUCTURE,1)
327 self.length += header.nbytes
333 self.length += header.nbytes
328 except Exception, e:
334 except Exception, e:
329 print "RadarControllerHeader: " + str(e)
335 print "RadarControllerHeader: " + str(e)
330 return 0
336 return 0
331
337
332 size = int(header['nSize'][0])
338 size = int(header['nSize'][0])
333 self.expType = int(header['nExpType'][0])
339 self.expType = int(header['nExpType'][0])
334 self.nTx = int(header['nNTx'][0])
340 self.nTx = int(header['nNTx'][0])
335 self.ipp = float(header['fIpp'][0])
341 self.ipp = float(header['fIpp'][0])
336 self.txA = float(header['fTxA'][0])
342 self.txA = float(header['fTxA'][0])
337 self.txB = float(header['fTxB'][0])
343 self.txB = float(header['fTxB'][0])
338 self.nWindows = int(header['nNumWindows'][0])
344 self.nWindows = int(header['nNumWindows'][0])
339 self.numTaus = int(header['nNumTaus'][0])
345 self.numTaus = int(header['nNumTaus'][0])
340 self.codeType = int(header['nCodeType'][0])
346 self.codeType = int(header['nCodeType'][0])
341 self.line6Function = int(header['nLine6Function'][0])
347 self.line6Function = int(header['nLine6Function'][0])
342 self.line5Function = int(header['nLine5Function'][0])
348 self.line5Function = int(header['nLine5Function'][0])
343 self.fClock = float(header['fClock'][0])
349 self.fClock = float(header['fClock'][0])
344 self.prePulseBefore = int(header['nPrePulseBefore'][0])
350 self.prePulseBefore = int(header['nPrePulseBefore'][0])
345 self.prePulserAfter = int(header['nPrePulseAfter'][0])
351 self.prePulserAfter = int(header['nPrePulseAfter'][0])
346 self.rangeIpp = header['sRangeIPP'][0]
352 self.rangeIpp = header['sRangeIPP'][0]
347 self.rangeTxA = header['sRangeTxA'][0]
353 self.rangeTxA = header['sRangeTxA'][0]
348 self.rangeTxB = header['sRangeTxB'][0]
354 self.rangeTxB = header['sRangeTxB'][0]
349
355
350 try:
356 try:
351 if hasattr(fp, 'read'):
357 if hasattr(fp, 'read'):
352 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
358 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
353 else:
359 else:
354 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
360 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
355 self.length += samplingWindow.nbytes
361 self.length += samplingWindow.nbytes
356 except Exception, e:
362 except Exception, e:
357 print "RadarControllerHeader: " + str(e)
363 print "RadarControllerHeader: " + str(e)
358 return 0
364 return 0
359 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
365 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
360 self.firstHeight = samplingWindow['h0']
366 self.firstHeight = samplingWindow['h0']
361 self.deltaHeight = samplingWindow['dh']
367 self.deltaHeight = samplingWindow['dh']
362 self.samplesWin = samplingWindow['nsa']
368 self.samplesWin = samplingWindow['nsa']
363
369
364
370
365
371
366 try:
372 try:
367 if hasattr(fp, 'read'):
373 if hasattr(fp, 'read'):
368 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
374 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
369 else:
375 else:
370 self.Taus = numpy.fromstring(fp[self.length:], '<f4', self.numTaus)
376 self.Taus = numpy.fromstring(fp[self.length:], '<f4', self.numTaus)
371 self.length += self.Taus.nbytes
377 self.length += self.Taus.nbytes
372 except Exception, e:
378 except Exception, e:
373 print "RadarControllerHeader: " + str(e)
379 print "RadarControllerHeader: " + str(e)
374 return 0
380 return 0
375
381
376
382
377
383
378 self.code_size = 0
384 self.code_size = 0
379 if self.codeType != 0:
385 if self.codeType != 0:
380
386
381 try:
387 try:
382 if hasattr(fp, 'read'):
388 if hasattr(fp, 'read'):
383 self.nCode = numpy.fromfile(fp, '<u4', 1)
389 self.nCode = numpy.fromfile(fp, '<u4', 1)
384 self.length += self.nCode.nbytes
390 self.length += self.nCode.nbytes
385 self.nBaud = numpy.fromfile(fp, '<u4', 1)
391 self.nBaud = numpy.fromfile(fp, '<u4', 1)
386 self.length += self.nBaud.nbytes
392 self.length += self.nBaud.nbytes
387 else:
393 else:
388 self.nCode = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
394 self.nCode = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
389 self.length += self.nCode.nbytes
395 self.length += self.nCode.nbytes
390 self.nBaud = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
396 self.nBaud = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
391 self.length += self.nBaud.nbytes
397 self.length += self.nBaud.nbytes
392 except Exception, e:
398 except Exception, e:
393 print "RadarControllerHeader: " + str(e)
399 print "RadarControllerHeader: " + str(e)
394 return 0
400 return 0
395 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
401 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
396
402
397 for ic in range(self.nCode):
403 for ic in range(self.nCode):
398 try:
404 try:
399 if hasattr(fp, 'read'):
405 if hasattr(fp, 'read'):
400 temp = numpy.fromfile(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
406 temp = numpy.fromfile(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
401 else:
407 else:
402 temp = numpy.fromstring(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
408 temp = numpy.fromstring(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
403 self.length += temp.nbytes
409 self.length += temp.nbytes
404 except Exception, e:
410 except Exception, e:
405 print "RadarControllerHeader: " + str(e)
411 print "RadarControllerHeader: " + str(e)
406 return 0
412 return 0
407
413
408 for ib in range(self.nBaud-1,-1,-1):
414 for ib in range(self.nBaud-1,-1,-1):
409 code[ic,ib] = temp[ib/32]%2
415 code[ic,ib] = temp[ib/32]%2
410 temp[ib/32] = temp[ib/32]/2
416 temp[ib/32] = temp[ib/32]/2
411
417
412 self.code = 2.0*code - 1.0
418 self.code = 2.0*code - 1.0
413 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
419 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
414
420
415 # if self.line5Function == RCfunction.FLIP:
421 # if self.line5Function == RCfunction.FLIP:
416 # self.flip1 = numpy.fromfile(fp,'<u4',1)
422 # self.flip1 = numpy.fromfile(fp,'<u4',1)
417 #
423 #
418 # if self.line6Function == RCfunction.FLIP:
424 # if self.line6Function == RCfunction.FLIP:
419 # self.flip2 = numpy.fromfile(fp,'<u4',1)
425 # self.flip2 = numpy.fromfile(fp,'<u4',1)
420 if startFp is not None:
426 if startFp is not None:
421 endFp = size + startFp
427 endFp = size + startFp
422
428
423 if fp.tell() != endFp:
429 if fp.tell() != endFp:
424 # fp.seek(endFp)
430 # fp.seek(endFp)
425 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" %(fp.name, fp.tell()-startFp, size)
431 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" %(fp.name, fp.tell()-startFp, size)
426 # return 0
432 # return 0
427
433
428 if fp.tell() > endFp:
434 if fp.tell() > endFp:
429 sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name)
435 sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name)
430 # return 0
436 # return 0
431
437
432 if fp.tell() < endFp:
438 if fp.tell() < endFp:
433 sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name)
439 sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name)
434
440
435
441
436 return 1
442 return 1
437
443
438 def write(self, fp):
444 def write(self, fp):
439
445
440 headerTuple = (self.size,
446 headerTuple = (self.size,
441 self.expType,
447 self.expType,
442 self.nTx,
448 self.nTx,
443 self.ipp,
449 self.ipp,
444 self.txA,
450 self.txA,
445 self.txB,
451 self.txB,
446 self.nWindows,
452 self.nWindows,
447 self.numTaus,
453 self.numTaus,
448 self.codeType,
454 self.codeType,
449 self.line6Function,
455 self.line6Function,
450 self.line5Function,
456 self.line5Function,
451 self.fClock,
457 self.fClock,
452 self.prePulseBefore,
458 self.prePulseBefore,
453 self.prePulserAfter,
459 self.prePulserAfter,
454 self.rangeIpp,
460 self.rangeIpp,
455 self.rangeTxA,
461 self.rangeTxA,
456 self.rangeTxB)
462 self.rangeTxB)
457
463
458 header = numpy.array(headerTuple,RADAR_STRUCTURE)
464 header = numpy.array(headerTuple,RADAR_STRUCTURE)
459 header.tofile(fp)
465 header.tofile(fp)
460
466
461 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
467 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
462 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
468 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
463 samplingWindow.tofile(fp)
469 samplingWindow.tofile(fp)
464
470
465 if self.numTaus > 0:
471 if self.numTaus > 0:
466 self.Taus.tofile(fp)
472 self.Taus.tofile(fp)
467
473
468 if self.codeType !=0:
474 if self.codeType !=0:
469 nCode = numpy.array(self.nCode, '<u4')
475 nCode = numpy.array(self.nCode, '<u4')
470 nCode.tofile(fp)
476 nCode.tofile(fp)
471 nBaud = numpy.array(self.nBaud, '<u4')
477 nBaud = numpy.array(self.nBaud, '<u4')
472 nBaud.tofile(fp)
478 nBaud.tofile(fp)
473 code1 = (self.code + 1.0)/2.
479 code1 = (self.code + 1.0)/2.
474
480
475 for ic in range(self.nCode):
481 for ic in range(self.nCode):
476 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
482 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
477 start = 0
483 start = 0
478 end = 32
484 end = 32
479 for i in range(len(tempx)):
485 for i in range(len(tempx)):
480 code_selected = code1[ic,start:end]
486 code_selected = code1[ic,start:end]
481 for j in range(len(code_selected)-1,-1,-1):
487 for j in range(len(code_selected)-1,-1,-1):
482 if code_selected[j] == 1:
488 if code_selected[j] == 1:
483 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
489 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
484 start = start + 32
490 start = start + 32
485 end = end + 32
491 end = end + 32
486
492
487 tempx = tempx.astype('u4')
493 tempx = tempx.astype('u4')
488 tempx.tofile(fp)
494 tempx.tofile(fp)
489
495
490 # if self.line5Function == RCfunction.FLIP:
496 # if self.line5Function == RCfunction.FLIP:
491 # self.flip1.tofile(fp)
497 # self.flip1.tofile(fp)
492 #
498 #
493 # if self.line6Function == RCfunction.FLIP:
499 # if self.line6Function == RCfunction.FLIP:
494 # self.flip2.tofile(fp)
500 # self.flip2.tofile(fp)
495
501
496 return 1
502 return 1
497
503
498 def get_ippSeconds(self):
504 def get_ippSeconds(self):
499 '''
505 '''
500 '''
506 '''
501 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
507 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
502
508
503 return ippSeconds
509 return ippSeconds
504
510
505 def set_ippSeconds(self, ippSeconds):
511 def set_ippSeconds(self, ippSeconds):
506 '''
512 '''
507 '''
513 '''
508
514
509 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
515 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
510
516
511 return
517 return
512
518
513 def get_size(self):
519 def get_size(self):
514
520
515 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
521 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
516
522
517 if self.codeType != 0:
523 if self.codeType != 0:
518 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
524 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
519
525
520 return self.__size
526 return self.__size
521
527
522 def set_size(self, value):
528 def set_size(self, value):
523
529
524 raise IOError, "size is a property and it cannot be set, just read"
530 raise IOError, "size is a property and it cannot be set, just read"
525
531
526 return
532 return
527
533
528 ippSeconds = property(get_ippSeconds, set_ippSeconds)
534 ippSeconds = property(get_ippSeconds, set_ippSeconds)
529 size = property(get_size, set_size)
535 size = property(get_size, set_size)
530
536
531 class ProcessingHeader(Header):
537 class ProcessingHeader(Header):
532
538
533 # size = None
539 # size = None
534 dtype = None
540 dtype = None
535 blockSize = None
541 blockSize = None
536 profilesPerBlock = None
542 profilesPerBlock = None
537 dataBlocksPerFile = None
543 dataBlocksPerFile = None
538 nWindows = None
544 nWindows = None
539 processFlags = None
545 processFlags = None
540 nCohInt = None
546 nCohInt = None
541 nIncohInt = None
547 nIncohInt = None
542 totalSpectra = None
548 totalSpectra = None
543
549 structure = PROCESSING_STRUCTURE
544 flag_dc = None
550 flag_dc = None
545 flag_cspc = None
551 flag_cspc = None
546
552
547 def __init__(self):
553 def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0,processFlags=0, nCohInt=0,
554 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
555 code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False
556 ):
548
557
549 # self.size = 0
558 # self.size = 0
550 self.dtype = 0
559 self.dtype = dtype
551 self.blockSize = 0
560 self.blockSize = blockSize
552 self.profilesPerBlock = 0
561 self.profilesPerBlock = 0
553 self.dataBlocksPerFile = 0
562 self.dataBlocksPerFile = 0
554 self.nWindows = 0
563 self.nWindows = 0
555 self.processFlags = 0
564 self.processFlags = 0
556 self.nCohInt = 0
565 self.nCohInt = 0
557 self.nIncohInt = 0
566 self.nIncohInt = 0
558 self.totalSpectra = 0
567 self.totalSpectra = 0
559
568
560 self.nHeights = 0
569 self.nHeights = 0
561 self.firstHeight = 0
570 self.firstHeight = 0
562 self.deltaHeight = 0
571 self.deltaHeight = 0
563 self.samplesWin = 0
572 self.samplesWin = 0
564 self.spectraComb = 0
573 self.spectraComb = 0
565 self.nCode = None
574 self.nCode = None
566 self.code = None
575 self.code = None
567 self.nBaud = None
576 self.nBaud = None
568
577
569 self.shif_fft = False
578 self.shif_fft = False
570 self.flag_dc = False
579 self.flag_dc = False
571 self.flag_cspc = False
580 self.flag_cspc = False
572 self.flag_decode = False
581 self.flag_decode = False
573 self.flag_deflip = False
582 self.flag_deflip = False
574 self.length = 0
583 self.length = 0
584
575 def read(self, fp):
585 def read(self, fp):
576 self.length = 0
586 self.length = 0
577 try:
587 try:
578 startFp = fp.tell()
588 startFp = fp.tell()
579 except Exception, e:
589 except Exception, e:
580 startFp = None
590 startFp = None
581 pass
591 pass
582
592
583 try:
593 try:
584 if hasattr(fp, 'read'):
594 if hasattr(fp, 'read'):
585 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
595 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
586 else:
596 else:
587 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
597 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
588 self.length += header.nbytes
598 self.length += header.nbytes
589 except Exception, e:
599 except Exception, e:
590 print "ProcessingHeader: " + str(e)
600 print "ProcessingHeader: " + str(e)
591 return 0
601 return 0
592
602
593 size = int(header['nSize'][0])
603 size = int(header['nSize'][0])
594 self.dtype = int(header['nDataType'][0])
604 self.dtype = int(header['nDataType'][0])
595 self.blockSize = int(header['nSizeOfDataBlock'][0])
605 self.blockSize = int(header['nSizeOfDataBlock'][0])
596 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
606 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
597 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
607 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
598 self.nWindows = int(header['nNumWindows'][0])
608 self.nWindows = int(header['nNumWindows'][0])
599 self.processFlags = header['nProcessFlags']
609 self.processFlags = header['nProcessFlags']
600 self.nCohInt = int(header['nCoherentIntegrations'][0])
610 self.nCohInt = int(header['nCoherentIntegrations'][0])
601 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
611 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
602 self.totalSpectra = int(header['nTotalSpectra'][0])
612 self.totalSpectra = int(header['nTotalSpectra'][0])
603
613
604 try:
614 try:
605 if hasattr(fp, 'read'):
615 if hasattr(fp, 'read'):
606 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
616 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
607 else:
617 else:
608 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
618 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
609 self.length += samplingWindow.nbytes
619 self.length += samplingWindow.nbytes
610 except Exception, e:
620 except Exception, e:
611 print "ProcessingHeader: " + str(e)
621 print "ProcessingHeader: " + str(e)
612 return 0
622 return 0
613
623
614 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
624 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
615 self.firstHeight = float(samplingWindow['h0'][0])
625 self.firstHeight = float(samplingWindow['h0'][0])
616 self.deltaHeight = float(samplingWindow['dh'][0])
626 self.deltaHeight = float(samplingWindow['dh'][0])
617 self.samplesWin = samplingWindow['nsa'][0]
627 self.samplesWin = samplingWindow['nsa'][0]
618
628
619
629
620 try:
630 try:
621 if hasattr(fp, 'read'):
631 if hasattr(fp, 'read'):
622 self.spectraComb = numpy.fromfile(fp, 'u1', 2*self.totalSpectra)
632 self.spectraComb = numpy.fromfile(fp, 'u1', 2*self.totalSpectra)
623 else:
633 else:
624 self.spectraComb = numpy.fromstring(fp[self.length:], 'u1', 2*self.totalSpectra)
634 self.spectraComb = numpy.fromstring(fp[self.length:], 'u1', 2*self.totalSpectra)
625 self.length += self.spectraComb.nbytes
635 self.length += self.spectraComb.nbytes
626 except Exception, e:
636 except Exception, e:
627 print "ProcessingHeader: " + str(e)
637 print "ProcessingHeader: " + str(e)
628 return 0
638 return 0
629
639
630 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
640 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
631 self.nCode = int(numpy.fromfile(fp,'<u4',1))
641 self.nCode = int(numpy.fromfile(fp,'<u4',1))
632 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
642 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
633 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
643 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
634
644
635 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
645 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
636 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
646 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
637 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
647 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
638
648
639 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
649 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
640 self.shif_fft = True
650 self.shif_fft = True
641 else:
651 else:
642 self.shif_fft = False
652 self.shif_fft = False
643
653
644 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
654 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
645 self.flag_dc = True
655 self.flag_dc = True
646 else:
656 else:
647 self.flag_dc = False
657 self.flag_dc = False
648
658
649 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
659 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
650 self.flag_decode = True
660 self.flag_decode = True
651 else:
661 else:
652 self.flag_decode = False
662 self.flag_decode = False
653
663
654 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
664 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
655 self.flag_deflip = True
665 self.flag_deflip = True
656 else:
666 else:
657 self.flag_deflip = False
667 self.flag_deflip = False
658
668
659 nChannels = 0
669 nChannels = 0
660 nPairs = 0
670 nPairs = 0
661 pairList = []
671 pairList = []
662
672
663 for i in range( 0, self.totalSpectra*2, 2 ):
673 for i in range( 0, self.totalSpectra*2, 2 ):
664 if self.spectraComb[i] == self.spectraComb[i+1]:
674 if self.spectraComb[i] == self.spectraComb[i+1]:
665 nChannels = nChannels + 1 #par de canales iguales
675 nChannels = nChannels + 1 #par de canales iguales
666 else:
676 else:
667 nPairs = nPairs + 1 #par de canales diferentes
677 nPairs = nPairs + 1 #par de canales diferentes
668 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
678 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
669
679
670 self.flag_cspc = False
680 self.flag_cspc = False
671 if nPairs > 0:
681 if nPairs > 0:
672 self.flag_cspc = True
682 self.flag_cspc = True
673
683
674
684
675
685
676 if startFp is not None:
686 if startFp is not None:
677 endFp = size + startFp
687 endFp = size + startFp
678 if fp.tell() > endFp:
688 if fp.tell() > endFp:
679 sys.stderr.write("Warning: Processing header size is lower than it has to be")
689 sys.stderr.write("Warning: Processing header size is lower than it has to be")
680 return 0
690 return 0
681
691
682 if fp.tell() < endFp:
692 if fp.tell() < endFp:
683 sys.stderr.write("Warning: Processing header size is greater than it is considered")
693 sys.stderr.write("Warning: Processing header size is greater than it is considered")
684
694
685 return 1
695 return 1
686
696
687 def write(self, fp):
697 def write(self, fp):
688 #Clear DEFINE_PROCESS_CODE
698 #Clear DEFINE_PROCESS_CODE
689 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
699 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
690
700
691 headerTuple = (self.size,
701 headerTuple = (self.size,
692 self.dtype,
702 self.dtype,
693 self.blockSize,
703 self.blockSize,
694 self.profilesPerBlock,
704 self.profilesPerBlock,
695 self.dataBlocksPerFile,
705 self.dataBlocksPerFile,
696 self.nWindows,
706 self.nWindows,
697 self.processFlags,
707 self.processFlags,
698 self.nCohInt,
708 self.nCohInt,
699 self.nIncohInt,
709 self.nIncohInt,
700 self.totalSpectra)
710 self.totalSpectra)
701
711
702 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
712 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
703 header.tofile(fp)
713 header.tofile(fp)
704
714
705 if self.nWindows != 0:
715 if self.nWindows != 0:
706 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
716 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
707 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
717 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
708 samplingWindow.tofile(fp)
718 samplingWindow.tofile(fp)
709
719
710 if self.totalSpectra != 0:
720 if self.totalSpectra != 0:
711 # spectraComb = numpy.array([],numpy.dtype('u1'))
721 # spectraComb = numpy.array([],numpy.dtype('u1'))
712 spectraComb = self.spectraComb
722 spectraComb = self.spectraComb
713 spectraComb.tofile(fp)
723 spectraComb.tofile(fp)
714
724
715 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
725 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
716 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
726 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
717 # nCode.tofile(fp)
727 # nCode.tofile(fp)
718 #
728 #
719 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
729 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
720 # nBaud.tofile(fp)
730 # nBaud.tofile(fp)
721 #
731 #
722 # code = self.code.reshape(self.nCode*self.nBaud)
732 # code = self.code.reshape(self.nCode*self.nBaud)
723 # code = code.astype(numpy.dtype('<f4'))
733 # code = code.astype(numpy.dtype('<f4'))
724 # code.tofile(fp)
734 # code.tofile(fp)
725
735
726 return 1
736 return 1
727
737
728 def get_size(self):
738 def get_size(self):
729
739
730 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
740 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
731
741
732 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
742 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
733 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
743 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
734 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
744 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
735
745
736 return self.__size
746 return self.__size
737
747
738 def set_size(self, value):
748 def set_size(self, value):
739
749
740 raise IOError, "size is a property and it cannot be set, just read"
750 raise IOError, "size is a property and it cannot be set, just read"
741
751
742 return
752 return
743
753
744 size = property(get_size, set_size)
754 size = property(get_size, set_size)
745
755
746 class RCfunction:
756 class RCfunction:
747 NONE=0
757 NONE=0
748 FLIP=1
758 FLIP=1
749 CODE=2
759 CODE=2
750 SAMPLING=3
760 SAMPLING=3
751 LIN6DIV256=4
761 LIN6DIV256=4
752 SYNCHRO=5
762 SYNCHRO=5
753
763
754 class nCodeType:
764 class nCodeType:
755 NONE=0
765 NONE=0
756 USERDEFINE=1
766 USERDEFINE=1
757 BARKER2=2
767 BARKER2=2
758 BARKER3=3
768 BARKER3=3
759 BARKER4=4
769 BARKER4=4
760 BARKER5=5
770 BARKER5=5
761 BARKER7=6
771 BARKER7=6
762 BARKER11=7
772 BARKER11=7
763 BARKER13=8
773 BARKER13=8
764 AC128=9
774 AC128=9
765 COMPLEMENTARYCODE2=10
775 COMPLEMENTARYCODE2=10
766 COMPLEMENTARYCODE4=11
776 COMPLEMENTARYCODE4=11
767 COMPLEMENTARYCODE8=12
777 COMPLEMENTARYCODE8=12
768 COMPLEMENTARYCODE16=13
778 COMPLEMENTARYCODE16=13
769 COMPLEMENTARYCODE32=14
779 COMPLEMENTARYCODE32=14
770 COMPLEMENTARYCODE64=15
780 COMPLEMENTARYCODE64=15
771 COMPLEMENTARYCODE128=16
781 COMPLEMENTARYCODE128=16
772 CODE_BINARY28=17
782 CODE_BINARY28=17
773
783
774 class PROCFLAG:
784 class PROCFLAG:
775
785
776 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
786 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
777 DECODE_DATA = numpy.uint32(0x00000002)
787 DECODE_DATA = numpy.uint32(0x00000002)
778 SPECTRA_CALC = numpy.uint32(0x00000004)
788 SPECTRA_CALC = numpy.uint32(0x00000004)
779 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
789 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
780 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
790 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
781 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
791 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
782
792
783 DATATYPE_CHAR = numpy.uint32(0x00000040)
793 DATATYPE_CHAR = numpy.uint32(0x00000040)
784 DATATYPE_SHORT = numpy.uint32(0x00000080)
794 DATATYPE_SHORT = numpy.uint32(0x00000080)
785 DATATYPE_LONG = numpy.uint32(0x00000100)
795 DATATYPE_LONG = numpy.uint32(0x00000100)
786 DATATYPE_INT64 = numpy.uint32(0x00000200)
796 DATATYPE_INT64 = numpy.uint32(0x00000200)
787 DATATYPE_FLOAT = numpy.uint32(0x00000400)
797 DATATYPE_FLOAT = numpy.uint32(0x00000400)
788 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
798 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
789
799
790 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
800 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
791 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
801 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
792 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
802 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
793
803
794 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
804 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
795 DEFLIP_DATA = numpy.uint32(0x00010000)
805 DEFLIP_DATA = numpy.uint32(0x00010000)
796 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
806 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
797
807
798 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
808 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
799 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
809 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
800 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
810 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
801 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
811 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
802 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
812 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
803
813
804 EXP_NAME_ESP = numpy.uint32(0x00200000)
814 EXP_NAME_ESP = numpy.uint32(0x00200000)
805 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
815 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
806
816
807 OPERATION_MASK = numpy.uint32(0x0000003F)
817 OPERATION_MASK = numpy.uint32(0x0000003F)
808 DATATYPE_MASK = numpy.uint32(0x00000FC0)
818 DATATYPE_MASK = numpy.uint32(0x00000FC0)
809 DATAARRANGE_MASK = numpy.uint32(0x00007000)
819 DATAARRANGE_MASK = numpy.uint32(0x00007000)
810 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
820 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
811
821
812 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
822 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
813 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
823 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
814 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
824 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
815 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
825 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
816 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
826 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
817 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
827 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
818
828
819 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
829 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
820
830
821 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
831 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
822 PROCFLAG.DATATYPE_SHORT,
832 PROCFLAG.DATATYPE_SHORT,
823 PROCFLAG.DATATYPE_LONG,
833 PROCFLAG.DATATYPE_LONG,
824 PROCFLAG.DATATYPE_INT64,
834 PROCFLAG.DATATYPE_INT64,
825 PROCFLAG.DATATYPE_FLOAT,
835 PROCFLAG.DATATYPE_FLOAT,
826 PROCFLAG.DATATYPE_DOUBLE]
836 PROCFLAG.DATATYPE_DOUBLE]
827
837
828 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
838 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
829
839
830 def get_dtype_index(numpy_dtype):
840 def get_dtype_index(numpy_dtype):
831
841
832 index = None
842 index = None
833
843
834 for i in range(len(NUMPY_DTYPE_LIST)):
844 for i in range(len(NUMPY_DTYPE_LIST)):
835 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
845 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
836 index = i
846 index = i
837 break
847 break
838
848
839 return index
849 return index
840
850
841 def get_numpy_dtype(index):
851 def get_numpy_dtype(index):
842
852
843 return NUMPY_DTYPE_LIST[index]
853 return NUMPY_DTYPE_LIST[index]
844
854
845 def get_procflag_dtype(index):
855 def get_procflag_dtype(index):
846
856
847 return PROCFLAG_DTYPE_LIST[index]
857 return PROCFLAG_DTYPE_LIST[index]
848
858
849 def get_dtype_width(index):
859 def get_dtype_width(index):
850
860
851 return DTYPE_WIDTH[index] No newline at end of file
861 return DTYPE_WIDTH[index]
@@ -1,631 +1,653
1
1
2 '''
2 '''
3 Created on Jul 3, 2014
3 Created on Jul 3, 2014
4
4
5 @author: roj-idl71
5 @author: roj-idl71
6 '''
6 '''
7 import os
7 import os
8 import datetime
8 import datetime
9 import numpy
9 import numpy
10 from profilehooks import coverage
10 from fractions import Fraction
11 from fractions import Fraction
11
12
12 try:
13 try:
13 from gevent import sleep
14 from gevent import sleep
14 except:
15 except:
15 from time import sleep
16 from time import sleep
16
17
17 from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader
18 from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader
18 from schainpy.model.data.jrodata import Voltage
19 from schainpy.model.data.jrodata import Voltage
19 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
20 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
20
21
21 try:
22 try:
22 import digital_rf
23 import digital_rf
23 except:
24 except:
24 print 'You should install "digital_rf" module if you want to read Digital RF data'
25 print 'You should install "digital_rf" module if you want to read Digital RF data'
25
26
26 class DigitalRFReader(ProcessingUnit):
27 class DigitalRFReader(ProcessingUnit):
27 '''
28 '''
28 classdocs
29 classdocs
29 '''
30 '''
30
31
31 def __init__(self, **kwargs):
32 def __init__(self, **kwargs):
32 '''
33 '''
33 Constructor
34 Constructor
34 '''
35 '''
35
36
36 ProcessingUnit.__init__(self, **kwargs)
37 ProcessingUnit.__init__(self, **kwargs)
37
38
38 self.dataOut = Voltage()
39 self.dataOut = Voltage()
39 self.__printInfo = True
40 self.__printInfo = True
40 self.__flagDiscontinuousBlock = False
41 self.__flagDiscontinuousBlock = False
41 self.__bufferIndex = 9999999
42 self.__bufferIndex = 9999999
42
43
43 self.__ippKm = None
44 self.__ippKm = None
44 self.__codeType = 0
45 self.__codeType = 0
45 self.__nCode = None
46 self.__nCode = None
46 self.__nBaud = None
47 self.__nBaud = None
47 self.__code = None
48 self.__code = None
48
49
49 def __getCurrentSecond(self):
50 def __getCurrentSecond(self):
50
51
51 return self.__thisUnixSample/self.__sample_rate
52 return self.__thisUnixSample/self.__sample_rate
52
53
53 thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.")
54 thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.")
54
55
55 def __setFileHeader(self):
56 def __setFileHeader(self):
56 '''
57 '''
57 In this method will be initialized every parameter of dataOut object (header, no data)
58 In this method will be initialized every parameter of dataOut object (header, no data)
58 '''
59 '''
59 ippSeconds = 1.0*self.__nSamples/self.__sample_rate
60 ippSeconds = 1.0*self.__nSamples/self.__sample_rate
60
61
61 nProfiles = 1.0/ippSeconds #Number of profiles in one second
62 nProfiles = 1.0/ippSeconds #Number of profiles in one second
62
63
63 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ippKm=self.__ippKm,
64 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ippKm=self.__ippKm,
64 txA=0,
65 txA=0,
65 txB=0,
66 txB=0,
66 nWindows=1,
67 nWindows=1,
67 nHeights=self.__nSamples,
68 nHeights=self.__nSamples,
68 firstHeight=self.__firstHeigth,
69 firstHeight=self.__firstHeigth,
69 deltaHeight=self.__deltaHeigth,
70 deltaHeight=self.__deltaHeigth,
70 codeType=self.__codeType,
71 codeType=self.__codeType,
71 nCode=self.__nCode, nBaud=self.__nBaud,
72 nCode=self.__nCode, nBaud=self.__nBaud,
72 code = self.__code)
73 code = self.__code)
73
74
74 self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
75 self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
75 nProfiles=nProfiles,
76 nProfiles=nProfiles,
76 nChannels=len(self.__channelList),
77 nChannels=len(self.__channelList),
77 adcResolution=14)
78 adcResolution=14)
78
79
79 self.dataOut.type = "Voltage"
80 self.dataOut.type = "Voltage"
80
81
81 self.dataOut.data = None
82 self.dataOut.data = None
82
83
83 self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')])
84 self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')])
84
85
85 # self.dataOut.nChannels = 0
86 # self.dataOut.nChannels = 0
86
87
87 # self.dataOut.nHeights = 0
88 # self.dataOut.nHeights = 0
88
89
89 self.dataOut.nProfiles = nProfiles
90 self.dataOut.nProfiles = nProfiles
90
91
91 self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth
92 self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth
92
93
93 self.dataOut.channelList = self.__channelList
94 self.dataOut.channelList = self.__channelList
94
95
95 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
96 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
96
97
97 # self.dataOut.channelIndexList = None
98 # self.dataOut.channelIndexList = None
98
99
99 self.dataOut.flagNoData = True
100 self.dataOut.flagNoData = True
100
101
101 #Set to TRUE if the data is discontinuous
102 #Set to TRUE if the data is discontinuous
102 self.dataOut.flagDiscontinuousBlock = False
103 self.dataOut.flagDiscontinuousBlock = False
103
104
104 self.dataOut.utctime = None
105 self.dataOut.utctime = None
105
106
106 self.dataOut.timeZone = self.__timezone/60 #timezone like jroheader, difference in minutes between UTC and localtime
107 self.dataOut.timeZone = self.__timezone/60 #timezone like jroheader, difference in minutes between UTC and localtime
107
108
108 self.dataOut.dstFlag = 0
109 self.dataOut.dstFlag = 0
109
110
110 self.dataOut.errorCount = 0
111 self.dataOut.errorCount = 0
111
112
112 self.dataOut.nCohInt = 1
113 self.dataOut.nCohInt = 1
113
114
114 self.dataOut.flagDecodeData = False #asumo que la data esta decodificada
115 self.dataOut.flagDecodeData = False #asumo que la data esta decodificada
115
116
116 self.dataOut.flagDeflipData = False #asumo que la data esta sin flip
117 self.dataOut.flagDeflipData = False #asumo que la data esta sin flip
117
118
118 self.dataOut.flagShiftFFT = False
119 self.dataOut.flagShiftFFT = False
119
120
120 self.dataOut.ippSeconds = ippSeconds
121 self.dataOut.ippSeconds = ippSeconds
121
122
122 #Time interval between profiles
123 #Time interval between profiles
123 #self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
124 #self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
124
125
125 self.dataOut.frequency = self.__frequency
126 self.dataOut.frequency = self.__frequency
126
127
127 self.dataOut.realtime = self.__online
128 self.dataOut.realtime = self.__online
128
129
129 def findDatafiles(self, path, startDate=None, endDate=None):
130 def findDatafiles(self, path, startDate=None, endDate=None):
130
131
131 if not os.path.isdir(path):
132 if not os.path.isdir(path):
132 return []
133 return []
133
134
134 try:
135 try:
135 digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
136 digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
136 except:
137 except:
137 digitalReadObj = digital_rf.DigitalRFReader(path)
138 digitalReadObj = digital_rf.DigitalRFReader(path)
138
139
139 channelNameList = digitalReadObj.get_channels()
140 channelNameList = digitalReadObj.get_channels()
140
141
141 if not channelNameList:
142 if not channelNameList:
142 return []
143 return []
143
144
144 metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0])
145 metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0])
145
146
146 sample_rate = metadata_dict['sample_rate'][0]
147 sample_rate = metadata_dict['sample_rate'][0]
147
148
148 this_metadata_file = digitalReadObj.get_metadata(channelNameList[0])
149 this_metadata_file = digitalReadObj.get_metadata(channelNameList[0])
149
150
150 try:
151 try:
151 timezone = this_metadata_file['timezone'].value
152 timezone = this_metadata_file['timezone'].value
152 except:
153 except:
153 timezone = 0
154 timezone = 0
154
155
155 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(channelNameList[0])/sample_rate - timezone
156 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(channelNameList[0])/sample_rate - timezone
156
157
157 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
158 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
158 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
159 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
159
160
160 if not startDate:
161 if not startDate:
161 startDate = startDatetime.date()
162 startDate = startDatetime.date()
162
163
163 if not endDate:
164 if not endDate:
164 endDate = endDatatime.date()
165 endDate = endDatatime.date()
165
166
166 dateList = []
167 dateList = []
167
168
168 thisDatetime = startDatetime
169 thisDatetime = startDatetime
169
170
170 while(thisDatetime<=endDatatime):
171 while(thisDatetime<=endDatatime):
171
172
172 thisDate = thisDatetime.date()
173 thisDate = thisDatetime.date()
173
174
174 if thisDate < startDate:
175 if thisDate < startDate:
175 continue
176 continue
176
177
177 if thisDate > endDate:
178 if thisDate > endDate:
178 break
179 break
179
180
180 dateList.append(thisDate)
181 dateList.append(thisDate)
181 thisDatetime += datetime.timedelta(1)
182 thisDatetime += datetime.timedelta(1)
182
183
183 return dateList
184 return dateList
184
185
185 def setup(self, path = None,
186 def setup(self, path = None,
186 startDate = None,
187 startDate = None,
187 endDate = None,
188 endDate = None,
188 startTime = datetime.time(0,0,0),
189 startTime = datetime.time(0,0,0),
189 endTime = datetime.time(23,59,59),
190 endTime = datetime.time(23,59,59),
190 channelList = None,
191 channelList = None,
191 nSamples = None,
192 nSamples = None,
192 ippKm = 60,
193 ippKm = 60,
193 online = False,
194 online = False,
194 delay = 60,
195 delay = 60,
195 buffer_size = 1024,
196 buffer_size = 1024,
196 **kwargs):
197 **kwargs):
197 '''
198 '''
198 In this method we should set all initial parameters.
199 In this method we should set all initial parameters.
199
200
200 Inputs:
201 Inputs:
201 path
202 path
202 startDate
203 startDate
203 endDate
204 endDate
204 startTime
205 startTime
205 endTime
206 endTime
206 set
207 set
207 expLabel
208 expLabel
208 ext
209 ext
209 online
210 online
210 delay
211 delay
211 '''
212 '''
212
213
213 if not os.path.isdir(path):
214 if not os.path.isdir(path):
214 raise ValueError, "[Reading] Directory %s does not exist" %path
215 raise ValueError, "[Reading] Directory %s does not exist" %path
215
216
216 try:
217 try:
217 self.digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
218 self.digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
218 except:
219 except:
219 self.digitalReadObj = digital_rf.DigitalRFReader(path)
220 self.digitalReadObj = digital_rf.DigitalRFReader(path)
220
221
221 channelNameList = self.digitalReadObj.get_channels()
222 channelNameList = self.digitalReadObj.get_channels()
222
223
223 if not channelNameList:
224 if not channelNameList:
224 raise ValueError, "[Reading] Directory %s does not have any files" %path
225 raise ValueError, "[Reading] Directory %s does not have any files" %path
225
226
226 if not channelList:
227 if not channelList:
227 channelList = range(len(channelNameList))
228 channelList = range(len(channelNameList))
228
229
229 ########## Reading metadata ######################
230 ########## Reading metadata ######################
230
231
231 metadata_dict = self.digitalReadObj.get_properties(channelNameList[channelList[0]])
232 metadata_dict = self.digitalReadObj.get_properties(channelNameList[channelList[0]])
232
233
233 self.__sample_rate = metadata_dict['sample_rate_numerator'] / metadata_dict['sample_rate_denominator']
234 self.__sample_rate = metadata_dict['sample_rate_numerator'] / metadata_dict['sample_rate_denominator']
234 # self.__samples_per_file = metadata_dict['samples_per_file'][0]
235 # self.__samples_per_file = metadata_dict['samples_per_file'][0]
235 self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15?
236 self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15?
236
237
237 this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]])
238 this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]])
238 metadata_bounds = this_metadata_file.get_bounds()
239 metadata_bounds = this_metadata_file.get_bounds()
239 self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ##GET FIRST HEADER
240 self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ##GET FIRST HEADER
240
241
241 self.__frequency = None
242 self.__frequency = None
242 try:
243 try:
243 self.__frequency = self.fixed_metadata_dict['frequency']
244 self.__frequency = self.fixed_metadata_dict['frequency']
244 except:
245 except:
245 self.__frequency = None
246 self.__frequency = None
246
247
247 try:
248 try:
248 self.__timezone = self.fixed_metadata_dict['timezone']
249 self.__timezone = self.fixed_metadata_dict['timezone']
249 except:
250 except:
250 self.__timezone = 0
251 self.__timezone = 0
251
252
252 self.__firstHeigth = 0
253 self.__firstHeigth = 0
253
254
254
255 try:
255 try:
256 codeType = self.fixed_metadata_dict['codeType']
256 codeType = self.fixed_metadata_dict['codeType']
257 except:
257 except:
258 codeType = 0
258 codeType = 0
259
259
260 nCode = 1
260 nCode = 1
261 nBaud = 1
261 nBaud = 1
262 code = numpy.ones((nCode, nBaud), dtype=numpy.int)
262 code = numpy.ones((nCode, nBaud), dtype=numpy.int)
263
263
264 if codeType:
264 if codeType:
265 nCode = self.fixed_metadata_dict['nCode']
265 nCode = self.fixed_metadata_dict['nCode']
266 nBaud = self.fixed_metadata_dict['nBaud']
266 nBaud = self.fixed_metadata_dict['nBaud']
267 code = self.fixed_metadata_dict['code']
267 code = self.fixed_metadata_dict['code']
268
268
269 if not ippKm:
269 if not ippKm:
270 try:
270 try:
271 #seconds to km
271 #seconds to km
272 ippKm = 1e6*0.15*self.fixed_metadata_dict['ipp']
272 ippKm = 1e6*0.15*self.fixed_metadata_dict['ipp']
273 except:
273 except:
274 ippKm = None
274 ippKm = None
275 ####################################################
275 ####################################################
276 startUTCSecond = None
276 startUTCSecond = None
277 endUTCSecond = None
277 endUTCSecond = None
278
278
279 if startDate:
279 if startDate:
280 startDatetime = datetime.datetime.combine(startDate, startTime)
280 startDatetime = datetime.datetime.combine(startDate, startTime)
281 startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
281 startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
282
282
283 if endDate:
283 if endDate:
284 endDatetime = datetime.datetime.combine(endDate, endTime)
284 endDatetime = datetime.datetime.combine(endDate, endTime)
285 endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
285 endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
286
286
287 start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]])
287 start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]])
288
288
289 if not startUTCSecond:
289 if not startUTCSecond:
290 startUTCSecond = start_index/self.__sample_rate
290 startUTCSecond = start_index/self.__sample_rate
291
291
292 if start_index > startUTCSecond*self.__sample_rate:
292 if start_index > startUTCSecond*self.__sample_rate:
293 startUTCSecond = start_index/self.__sample_rate
293 startUTCSecond = start_index/self.__sample_rate
294
294
295 if not endUTCSecond:
295 if not endUTCSecond:
296 endUTCSecond = end_index/self.__sample_rate
296 endUTCSecond = end_index/self.__sample_rate
297
297
298 if end_index < endUTCSecond*self.__sample_rate:
298 if end_index < endUTCSecond*self.__sample_rate:
299 endUTCSecond = end_index/self.__sample_rate
299 endUTCSecond = end_index/self.__sample_rate
300
300
301 if not nSamples:
301 if not nSamples:
302 if not ippKm:
302 if not ippKm:
303 raise ValueError, "[Reading] nSamples or ippKm should be defined"
303 raise ValueError, "[Reading] nSamples or ippKm should be defined"
304 nSamples = int(ippKm / (1e6*0.15/self.__sample_rate))
304 nSamples = int(ippKm / (1e6*0.15/self.__sample_rate))
305
305
306 channelBoundList = []
306 channelBoundList = []
307 channelNameListFiltered = []
307 channelNameListFiltered = []
308
308
309 for thisIndexChannel in channelList:
309 for thisIndexChannel in channelList:
310 thisChannelName = channelNameList[thisIndexChannel]
310 thisChannelName = channelNameList[thisIndexChannel]
311 start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName)
311 start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName)
312 channelBoundList.append((start_index, end_index))
312 channelBoundList.append((start_index, end_index))
313 channelNameListFiltered.append(thisChannelName)
313 channelNameListFiltered.append(thisChannelName)
314
314
315 self.profileIndex = 0
315 self.profileIndex = 0
316
316
317 self.__delay = delay
317 self.__delay = delay
318 self.__ippKm = ippKm
318 self.__ippKm = ippKm
319 self.__codeType = codeType
319 self.__codeType = codeType
320 self.__nCode = nCode
320 self.__nCode = nCode
321 self.__nBaud = nBaud
321 self.__nBaud = nBaud
322 self.__code = code
322 self.__code = code
323
323
324 self.__datapath = path
324 self.__datapath = path
325 self.__online = online
325 self.__online = online
326 self.__channelList = channelList
326 self.__channelList = channelList
327 self.__channelNameList = channelNameListFiltered
327 self.__channelNameList = channelNameListFiltered
328 self.__channelBoundList = channelBoundList
328 self.__channelBoundList = channelBoundList
329 self.__nSamples = nSamples
329 self.__nSamples = nSamples
330 self.__samples_to_read = long(buffer_size*nSamples) #FIJO: AHORA 40
330 self.__samples_to_read = long(buffer_size*nSamples) #FIJO: AHORA 40
331 self.__nChannels = len(self.__channelList)
331 self.__nChannels = len(self.__channelList)
332
332
333 self.__startUTCSecond = startUTCSecond
333 self.__startUTCSecond = startUTCSecond
334 self.__endUTCSecond = endUTCSecond
334 self.__endUTCSecond = endUTCSecond
335
335
336 self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate #Time interval
336 self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate #Time interval
337
337
338 if online:
338 if online:
339 # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read)
339 # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read)
340 startUTCSecond = numpy.floor(endUTCSecond)
340 startUTCSecond = numpy.floor(endUTCSecond)
341
341
342 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
342 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
343
343
344 self.__data_buffer = numpy.zeros((self.__nChannels, self.__samples_to_read), dtype = numpy.complex)
344 self.__data_buffer = numpy.zeros((self.__nChannels, self.__samples_to_read), dtype = numpy.complex)
345
345
346 self.__setFileHeader()
346 self.__setFileHeader()
347 self.isConfig = True
347 self.isConfig = True
348
348
349 print "[Reading] Digital RF Data was found from %s to %s " %(
349 print "[Reading] Digital RF Data was found from %s to %s " %(
350 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
350 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
351 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
351 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
352 )
352 )
353
353
354 print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone),
354 print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone),
355 datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone)
355 datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone)
356 )
356 )
357
357
358 def __reload(self):
358 def __reload(self):
359 # print
359 # print
360 # print "%s not in range [%s, %s]" %(
360 # print "%s not in range [%s, %s]" %(
361 # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
361 # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
362 # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
362 # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
363 # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
363 # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
364 # )
364 # )
365 print "[Reading] reloading metadata ..."
365 print "[Reading] reloading metadata ..."
366
366
367 try:
367 try:
368 self.digitalReadObj.reload(complete_update=True)
368 self.digitalReadObj.reload(complete_update=True)
369 except:
369 except:
370 self.digitalReadObj.reload()
370 self.digitalReadObj.reload()
371
371
372 start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]])
372 start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]])
373
373
374 if start_index > self.__startUTCSecond*self.__sample_rate:
374 if start_index > self.__startUTCSecond*self.__sample_rate:
375 self.__startUTCSecond = 1.0*start_index/self.__sample_rate
375 self.__startUTCSecond = 1.0*start_index/self.__sample_rate
376
376
377 if end_index > self.__endUTCSecond*self.__sample_rate:
377 if end_index > self.__endUTCSecond*self.__sample_rate:
378 self.__endUTCSecond = 1.0*end_index/self.__sample_rate
378 self.__endUTCSecond = 1.0*end_index/self.__sample_rate
379 print
379 print
380 print "[Reading] New timerange found [%s, %s] " %(
380 print "[Reading] New timerange found [%s, %s] " %(
381 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
381 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
382 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
382 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
383 )
383 )
384
384
385 return True
385 return True
386
386
387 return False
387 return False
388
388
389 def __readNextBlock(self, seconds=30, volt_scale = 218776):
389 def __readNextBlock(self, seconds=30, volt_scale = 1):
390 '''
390 '''
391 '''
391 '''
392
392
393 #Set the next data
393 #Set the next data
394 self.__flagDiscontinuousBlock = False
394 self.__flagDiscontinuousBlock = False
395 self.__thisUnixSample += self.__samples_to_read
395 self.__thisUnixSample += self.__samples_to_read
396
396
397 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
397 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
398 print "[Reading] There are no more data into selected time-range"
398 print "[Reading] There are no more data into selected time-range"
399 if self.__online:
399 if self.__online:
400 self.__reload()
400 self.__reload()
401 else:
401 else:
402 return False
402 return False
403
403
404 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
404 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
405 return False
405 return False
406 self.__thisUnixSample -= self.__samples_to_read
406 self.__thisUnixSample -= self.__samples_to_read
407
407
408 indexChannel = 0
408 indexChannel = 0
409
409
410 dataOk = False
410 dataOk = False
411
411
412 for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS?
412 for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS?
413
413
414 try:
414 try:
415 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
415 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
416 self.__samples_to_read,
416 self.__samples_to_read,
417 thisChannelName)
417 thisChannelName)
418 except IOError, e:
418 except IOError, e:
419 #read next profile
419 #read next profile
420 self.__flagDiscontinuousBlock = True
420 self.__flagDiscontinuousBlock = True
421 print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
421 print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
422 break
422 break
423
423
424 if result.shape[0] != self.__samples_to_read:
424 if result.shape[0] != self.__samples_to_read:
425 self.__flagDiscontinuousBlock = True
425 self.__flagDiscontinuousBlock = True
426 print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
426 print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
427 result.shape[0],
427 result.shape[0],
428 self.__samples_to_read)
428 self.__samples_to_read)
429 break
429 break
430
430
431 self.__data_buffer[indexChannel,:] = result*volt_scale
431 self.__data_buffer[indexChannel,:] = result*volt_scale
432
432
433 indexChannel += 1
433 indexChannel += 1
434
434
435 dataOk = True
435 dataOk = True
436
436
437 self.__utctime = self.__thisUnixSample/self.__sample_rate
437 self.__utctime = self.__thisUnixSample/self.__sample_rate
438
438
439 if not dataOk:
439 if not dataOk:
440 return False
440 return False
441
441
442 print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
442 print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
443 self.__samples_to_read,
443 self.__samples_to_read,
444 self.__timeInterval)
444 self.__timeInterval)
445
445
446 self.__bufferIndex = 0
446 self.__bufferIndex = 0
447
447
448 return True
448 return True
449
449
450 def __isBufferEmpty(self):
450 def __isBufferEmpty(self):
451 return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40
451 return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40
452
452
453 def getData(self, seconds=30, nTries=5):
453 def getData(self, seconds=30, nTries=5):
454
454
455 '''
455 '''
456 This method gets the data from files and put the data into the dataOut object
456 This method gets the data from files and put the data into the dataOut object
457
457
458 In addition, increase el the buffer counter in one.
458 In addition, increase el the buffer counter in one.
459
459
460 Return:
460 Return:
461 data : retorna un perfil de voltages (alturas * canales) copiados desde el
461 data : retorna un perfil de voltages (alturas * canales) copiados desde el
462 buffer. Si no hay mas archivos a leer retorna None.
462 buffer. Si no hay mas archivos a leer retorna None.
463
463
464 Affected:
464 Affected:
465 self.dataOut
465 self.dataOut
466 self.profileIndex
466 self.profileIndex
467 self.flagDiscontinuousBlock
467 self.flagDiscontinuousBlock
468 self.flagIsNewBlock
468 self.flagIsNewBlock
469 '''
469 '''
470
470
471 err_counter = 0
471 err_counter = 0
472 self.dataOut.flagNoData = True
472 self.dataOut.flagNoData = True
473
473
474 if self.__isBufferEmpty():
474 if self.__isBufferEmpty():
475
475
476 self.__flagDiscontinuousBlock = False
476 self.__flagDiscontinuousBlock = False
477
477
478 while True:
478 while True:
479 if self.__readNextBlock():
479 if self.__readNextBlock():
480 break
480 break
481 if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate:
481 if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate:
482 return False
482 return False
483
483
484 if self.__flagDiscontinuousBlock:
484 if self.__flagDiscontinuousBlock:
485 print '[Reading] discontinuous block found ... continue with the next block'
485 print '[Reading] discontinuous block found ... continue with the next block'
486 continue
486 continue
487
487
488 if not self.__online:
488 if not self.__online:
489 return False
489 return False
490
490
491 err_counter += 1
491 err_counter += 1
492 if err_counter > nTries:
492 if err_counter > nTries:
493 return False
493 return False
494
494
495 print '[Reading] waiting %d seconds to read a new block' %seconds
495 print '[Reading] waiting %d seconds to read a new block' %seconds
496 sleep(seconds)
496 sleep(seconds)
497
497
498 self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples]
498 self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples]
499 self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate
499 self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate
500 self.dataOut.flagNoData = False
500 self.dataOut.flagNoData = False
501 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
501 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
502 self.dataOut.profileIndex = self.profileIndex
502 self.dataOut.profileIndex = self.profileIndex
503
503
504 self.__bufferIndex += self.__nSamples
504 self.__bufferIndex += self.__nSamples
505 self.profileIndex += 1
505 self.profileIndex += 1
506
506
507 if self.profileIndex == self.dataOut.nProfiles:
507 if self.profileIndex == self.dataOut.nProfiles:
508 self.profileIndex = 0
508 self.profileIndex = 0
509
509
510 return True
510 return True
511
511
512 def printInfo(self):
512 def printInfo(self):
513 '''
513 '''
514 '''
514 '''
515 if self.__printInfo == False:
515 if self.__printInfo == False:
516 return
516 return
517
517
518 # self.systemHeaderObj.printInfo()
518 # self.systemHeaderObj.printInfo()
519 # self.radarControllerHeaderObj.printInfo()
519 # self.radarControllerHeaderObj.printInfo()
520
520
521 self.__printInfo = False
521 self.__printInfo = False
522
522
523 def printNumberOfBlock(self):
523 def printNumberOfBlock(self):
524 '''
524 '''
525 '''
525 '''
526 return
526 return
527 #print self.profileIndex
527 #print self.profileIndex
528
528
529 def run(self, **kwargs):
529 def run(self, **kwargs):
530 '''
530 '''
531 This method will be called many times so here you should put all your code
531 This method will be called many times so here you should put all your code
532 '''
532 '''
533
533
534 if not self.isConfig:
534 if not self.isConfig:
535 self.setup(**kwargs)
535 self.setup(**kwargs)
536
536
537 self.getData(seconds=self.__delay)
537 self.getData(seconds=self.__delay)
538
538
539 return
539 return
540
540
541 class DigitalRFWriter(Operation):
541 class DigitalRFWriter(Operation):
542 '''
542 '''
543 classdocs
543 classdocs
544 '''
544 '''
545
545
546 def __init__(self, **kwargs):
546 def __init__(self, **kwargs):
547 '''
547 '''
548 Constructor
548 Constructor
549 '''
549 '''
550 Operation.__init__(self, **kwargs)
550 Operation.__init__(self, **kwargs)
551 self.dataOut = None
551 self.dataOut = None
552
552
553 def setup(self, dataIn, path, set=0, ext='.h5'):
553 def setup(self, dataOut, path, set=0, metadataFile='metadata', ext='.h5'):
554 '''
554 '''
555 In this method we should set all initial parameters.
555 In this method we should set all initial parameters.
556
556
557 Input:
557 Input:
558 dataIn : Input data will also be outputa data
558 dataOut : Input data will also be outputa data
559
559
560 '''
560 '''
561
561
562 self.__ippSeconds = dataIn.ippSeconds
562 self.__ippSeconds = dataOut.ippSeconds
563 self.__deltaH = dataIn.getDeltaH()
563 self.__deltaH = dataOut.getDeltaH()
564 self.__sample_rate = 1e6*0.15/self.__deltaH
564 self.__sample_rate = 1e6*0.15/self.__deltaH
565 self.__dtype = dataIn.dtype
565 self.__dtype = dataOut.dtype
566 if len(dataIn.dtype) == 2:
566 if len(dataOut.dtype) == 2:
567 self.__dtype = dataIn.dtype[0]
567 self.__dtype = dataOut.dtype[0]
568 self.__nSamples = dataIn.systemHeaderObj.nSamples
568 self.__nSamples = dataOut.systemHeaderObj.nSamples
569 self.__nProfiles = dataIn.nProfiles
569 self.__nProfiles = dataOut.nProfiles
570 self.__blocks_per_file = dataIn.processingHeaderObj.dataBlocksPerFile
570 self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile
571
571 self.arr_data = arr_data = numpy.ones((self.__nSamples, 1), dtype=[('r', self.__dtype), ('i', self.__dtype)])
572 file_cadence_millisecs = 1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate * 1000
572
573 sub_cadence_secs = 10 * file_cadence_millisecs
573 file_cadence_millisecs = long(1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate * 1000)
574 sub_cadence_secs = file_cadence_millisecs
575
576 #print file_cadence_millisecs
577 #print sub_cadence_secs
578
574 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
579 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
575 sample_rate_numerator = long(sample_rate_fraction.numerator)
580 sample_rate_numerator = long(sample_rate_fraction.numerator)
576 sample_rate_denominator = long(sample_rate_fraction.denominator)
581 sample_rate_denominator = long(sample_rate_fraction.denominator)
577 start_global_index = dataIn.utctime * self.__sample_rate
582 start_global_index = dataOut.utctime * self.__sample_rate
578 self.arr_data = arr_data = numpy.ones((self.__nSamples, 1), dtype=[('r', self.__dtype), ('i', self.__dtype)])
583
579 uuid = 'prueba'
584 uuid = 'prueba'
580 compression_level = 1
585 compression_level = 1
581 checksum = False
586 checksum = False
582 is_complex = True
587 is_complex = True
583 num_subchannels = 1
588 num_subchannels = 1
584 is_continuous = True
589 is_continuous = True
585 marching_periods = False
590 marching_periods = False
586
591
587 self.digitalWriteObj = digital_rf.DigitalRFWriter("/home/jchavez/jicamarca/mocked_data/voltage", self.__dtype, sub_cadence_secs,
592 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, sub_cadence_secs,
588 file_cadence_millisecs, start_global_index,
593 file_cadence_millisecs, start_global_index,
589 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
594 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
590 is_complex, num_subchannels, is_continuous, marching_periods)
595 is_complex, num_subchannels, is_continuous, marching_periods)
596
597 metadata_dir = os.path.join(path, 'metadata')
598 os.system('mkdir %s' % (metadata_dir))
599
600 self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, 236, file_cadence_millisecs / 1000,
601 sample_rate_numerator, sample_rate_denominator,
602 metadataFile)
591
603
592
604
593 self.isConfig = True
605 self.isConfig = True
594
606 self.currentSample = 0
595 return
607 return
596
608
597 def run(self, dataIn, path=None, **kwargs):
609 @coverage
610 def run(self, dataOut, path=None, **kwargs):
598 '''
611 '''
599 This method will be called many times so here you should put all your code
612 This method will be called many times so here you should put all your code
600
613
601 Inputs:
614 Inputs:
602
615
603 dataIn : object with the data
616 dataOut : object with the data
604
617
605 '''
618 '''
606
619 #print dataOut.__dict__
607 self.dataOut = dataIn
620 self.dataOut = dataOut
608
621
609 if not self.isConfig:
622 if not self.isConfig:
610 self.setup(dataIn, path, **kwargs)
623 self.setup(dataOut, path, **kwargs)
611
624
612 samples = len(self.dataOut.data[0])
625 samples = len(self.dataOut.data[0])
613
626
614 for i in range(samples):
627 for i in range(samples):
615 self.arr_data[i]['r'] = dataIn.data[0][i].real
628 self.arr_data[i]['r'] = dataOut.data[0][i].real
616 self.arr_data[i]['i'] = dataIn.data[0][i].imag
629 self.arr_data[i]['i'] = dataOut.data[0][i].imag
617
618 if dataIn.flagNoData:
619 self.digitalWriteObj.close()
620
621 self.digitalWriteObj.rf_write(self.arr_data)
630 self.digitalWriteObj.rf_write(self.arr_data)
622
631 start_idx = self.__sample_rate * dataOut.utctime
632 metadata_dict = {}
633 metadata_dict['frequency'] = 49.92e6
634 metadata_dict['blablabla'] = 49.92e6
635 self.currentSample += 1
636 if self.dataOut.flagDataAsBlock:
637 self.digitalMetadataWriteObj.write(start_idx, metadata_dict)
638 elif self.currentSample == 1:
639 print '[Writing] - Writing metadata'
640 self.digitalMetadataWriteObj.write(start_idx, metadata_dict)
641 if self.currentSample == self.__nProfiles: self.currentSample = 0
642 def close(self):
643 print '[Writing] - Closing files '
644 self.digitalWriteObj.close()
623 #raise
645 #raise
624 if __name__ == '__main__':
646 if __name__ == '__main__':
625
647
626 readObj = DigitalRFReader()
648 readObj = DigitalRFReader()
627
649
628 while True:
650 while True:
629 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
651 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
630 # readObj.printInfo()
652 # readObj.printInfo()
631 readObj.printNumberOfBlock()
653 #readObj.printNumberOfBlock()
@@ -1,1 +1,1
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="VoltageReader" id="1911" inputId="0" name="VoltageReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="VoltageReader" /><Parameter format="str" id="191112" name="path" value="/home/jchavez/jicamarca/jro_data/rawdata" /><Parameter format="date" id="191113" name="startDate" value="2010/10/28" /><Parameter format="date" id="191114" name="endDate" value="2017/10/28" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="0" /></Operation><Operation id="19112" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="VoltageProc" id="1912" inputId="1911" name="VoltageProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="DigitalRFWriter" priority="2" type="other"><Parameter format="str" id="191221" name="path" value="/home/jchavez/jicamarca/data_sink/" /></Operation></ProcUnit></Project> No newline at end of file
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="VoltageReader" id="1911" inputId="0" name="VoltageReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="VoltageReader" /><Parameter format="str" id="191112" name="path" value="/home/jchavez/jicamarca/jro_data/rawdata" /><Parameter format="date" id="191113" name="startDate" value="2010/10/28" /><Parameter format="date" id="191114" name="endDate" value="2017/10/28" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="0" /></Operation><Operation id="19112" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="VoltageProc" id="1912" inputId="1911" name="VoltageProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="DigitalRFWriter" priority="2" type="other"><Parameter format="str" id="191221" name="path" value="/home/jchavez/jicamarca/mocked_data/voltage" /></Operation></ProcUnit></Project> No newline at end of file
@@ -1,94 +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/jchavez/jicamarca/jro_data/rawdata/',
15 path='/home/jchavez/jicamarca/jro_data/rawdata/',
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')
29 # opObj11.addParameter(name='id', value='121', format='int')
30 # opObj11.addParameter(name='wintitle', value='Scope', format='str')
31
28 opObj10 = procUnitConfObj0.addOperation(name='DigitalRFWriter', optype='other')
32 opObj10 = procUnitConfObj0.addOperation(name='DigitalRFWriter', optype='other')
29 opObj10.addParameter(name='path', value='/home/jchavez/jicamarca/data_sink/', format='str')
33 opObj10.addParameter(name='path', value='/home/jchavez/jicamarca/mocked_data/voltage', format='str')
30 # opObj10.addParameter(name='minHei', value='0', format='float')
34 # opObj10.addParameter(name='minHei', value='0', format='float')
31 # opObj10.addParameter(name='maxHei', value='8', format='float')
35 # opObj10.addParameter(name='maxHei', value='8', format='float')
32
36
33 # opObj10 = procUnitConfObj0.addOperation(name='filterByHeights')
37 # opObj10 = procUnitConfObj0.addOperation(name='filterByHeights')
34 # opObj10.addParameter(name='window', value='2', format='float')
38 # opObj10.addParameter(name='window', value='2', format='float')
35
39
36 # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external')
40 # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external')
37 # opObj10.addParameter(name='code', value='1,-1', format='intlist')
41 # opObj10.addParameter(name='code', value='1,-1', format='intlist')
38 # opObj10.addParameter(name='nCode', value='2', format='float')
42 # opObj10.addParameter(name='nCode', value='2', format='float')
39 # opObj10.addParameter(name='nBaud', value='1', format='float')
43 # opObj10.addParameter(name='nBaud', value='1', format='float')
40
44
41
45
42 # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
46 # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
43 # opObj10.addParameter(name='n', value='1296', format='float')
47 # opObj10.addParameter(name='n', value='1296', format='float')
44
48
45 # procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc',
49 # procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc',
46 # inputId=procUnitConfObj0.getId())
50 # inputId=procUnitConfObj0.getId())
47
51
48 #Creating a processing object with its parameters
52 #Creating a processing object with its parameters
49 #schainpy.model.proc.jroproc_spectra.SpectraProc.run()
53 #schainpy.model.proc.jroproc_spectra.SpectraProc.run()
50 #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"
51 # procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int')
55 # procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int')
52
56
53 # opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external')
57 # opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external')
54 # opObj10.addParameter(name='n', value='2', format='float')
58 # opObj10.addParameter(name='n', value='2', format='float')
55
59
56 #Using internal methods
60 #Using internal methods
57 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels()
61 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels()
58 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
62 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
59 # opObj10.addParameter(name='channelList', value='0,1', format='intlist')
63 # opObj10.addParameter(name='channelList', value='0,1', format='intlist')
60
64
61 #Using internal methods
65 #Using internal methods
62 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights()
66 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights()
63 # opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
67 # opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
64 # opObj10.addParameter(name='minHei', value='90', format='float')
68 # opObj10.addParameter(name='minHei', value='90', format='float')
65 # opObj10.addParameter(name='maxHei', value='180', format='float')
69 # opObj10.addParameter(name='maxHei', value='180', format='float')
66
70
67 #Using external methods (new modules)
71 #Using external methods (new modules)
68 # #schainpy.model.proc.jroproc_spectra.IncohInt.setup()
72 # #schainpy.model.proc.jroproc_spectra.IncohInt.setup()
69 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
73 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
70 # opObj12.addParameter(name='n', value='1', format='int')
74 # opObj12.addParameter(name='n', value='1', format='int')
71
75
72 #Using external methods (new modules)
76 #Using external methods (new modules)
73 #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup()
77 #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup()
74 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
78 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
75 # opObj11.addParameter(name='id', value='11', format='int')
79 # opObj11.addParameter(name='id', value='11', format='int')
76 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
80 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
77 # opObj11.addParameter(name='zmin', value='-60', format='int')
81 # opObj11.addParameter(name='zmin', value='-60', format='int')
78 # opObj11.addParameter(name='zmax', value='10', format='int')
82 # opObj11.addParameter(name='zmax', value='10', format='int')
79 # opObj11.addParameter(name='save', value='1', format='int')
83 # opObj11.addParameter(name='save', value='1', format='int')
80
84
81 # #Using external methods (new modules)
85 # #Using external methods (new modules)
82 # #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup()
86 # #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup()
83 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
87 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
84 # opObj11.addParameter(name='id', value='30', format='int')
88 # opObj11.addParameter(name='id', value='30', format='int')
85 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
89 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
86 # opObj11.addParameter(name='zmin', value='-60', format='int')
90 # opObj11.addParameter(name='zmin', value='-60', format='int')
87 # opObj11.addParameter(name='zmax', value='-10', format='int')
91 # opObj11.addParameter(name='zmax', value='-10', format='int')
88 # opObj11.addParameter(name='showprofile', value='1', format='int')
92 # opObj11.addParameter(name='showprofile', value='1', format='int')
89 # # 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')
90 # opObj11.addParameter(name='xmin', value='14', format='float')
94 # opObj11.addParameter(name='xmin', value='14', format='float')
91 # opObj11.addParameter(name='xmax', value='23.9', format='float')
95 # opObj11.addParameter(name='xmax', value='23.9', format='float')
92 # opObj11.addParameter(name='save', value='1', format='int')
96 # opObj11.addParameter(name='save', value='1', format='int')
93
97
94 controllerObj.start()
98 controllerObj.start()
General Comments 0
You need to be logged in to leave comments. Login now