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