##// END OF EJS Templates
Desarrollo de codigo para el calculo de Correlaciones....
Daniel Valdez -
r100:9b881802afd2
parent child
Show More
@@ -5,20 +5,35 Created on 23/01/2012
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 from JRODataIO import JRODataIO
8 import os, sys
9 import numpy
10 import glob
11 import fnmatch
12 import time, datetime
9
13
10 class CorrelationReader(JRODataIO):
14 path = os.path.split(os.getcwd())[0]
15 sys.path.append(path)
16
17 from Model.JROHeader import *
18 from Model.Voltage import Voltage
19
20 from IO.JRODataIO import JRODataReader
21 from IO.JRODataIO import JRODataWriter
22
23
24 class CorrelationReader(JRODataReader):#JRODataReader para lectura de correlaciones en archivos HDF5
11
25
12 def __init__(self):
26 def __init__(self):
13
27
14 pass
28 pass
15
29
16 class CorrelationWriter(JRODataIO):
30 class CorrelationWriter(JRODataWriter):#JRODataWriter para escritura de correlaciones en archivos HDF5
17
31
18 def __init__(self):
32 def __init__(self):
33
19 pass
34 pass
20
35
21 def putData(self):
36 def puData(self):
22 pass
37 pass
23
38
24 def writeBlock(self):
39 def writeBlock(self):
@@ -33,7 +33,7 class Correlation(JROData):
33
33
34 self.m_NoiseObj = Noise()
34 self.m_NoiseObj = Noise()
35
35
36 self.type = "Spectra"
36 self.type = "Correlation"
37
37
38 self.dataType = None
38 self.dataType = None
39
39
@@ -54,5 +54,7 class Correlation(JROData):
54
54
55 self.nLags = 0
55 self.nLags = 0
56
56
57 self.lagsList = None
57 self.tauList = None
58
59 self.pairList = None
58 No newline at end of file
60
@@ -5,18 +5,142 Created on Feb 7, 2012
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 import os, sys
9 import numpy
10
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
13
14 from Model.Correlation import Correlation
15 from IO.CorrelationIO import CorrelationWriter
16 #from Graphics.CorrelationPlot import Correlator
17
18
19 from Model.Voltage import Voltage
20 from Model.Spectra import Spectra
21
8 class CorrelationProcessor:
22 class CorrelationProcessor:
9 '''
23 '''
10 classdocs
24 classdocs
11 '''
25 '''
12
26
13
27 integratorIndex = None
14 def __init__(self):
28 writerIndex = None
29 plotterIndex = None
30
31 lagsList = None
32
33 nLags = None
34 tauList = None
35 pairList = None
36 indexTau = None
37
38
39 def __init__(self,dataInObj, dataOutObj=None):
15 '''
40 '''
16 Constructor
41 Constructor
17 '''
42 '''
18 pass
43 self.dataInObj = dataInObj
19 m_Correlation= Correlation()
44
45 if dataOutObj == None:
46 self.dataOutObj = Correlation()
47 else:
48 self.dataOutObj = dataOutObj
49
50 self.indexTau = 0
51 self.buffer = None
52
53 def init(self,pairList=None,tauList=None):
54
55 self.integratorIndex = 0
56 self.writerIndex = 0
57 self.plotterIndex = 0
58
59 self.pairList = pairList
60 self.tauList = tauList
61
62 if ( isinstance(self.dataInObj, Voltage) ):
63 self.__getCorrelation()
64
65 if ( isinstance(self.dataInObj, Spectra) ):
66 sys.exit(0)
67
68 if ( isinstance(self.dataInObj, Correlation) ):
69 sel.__getCopy()
70
71 def __getCorrelation(self):
72 if self.dataInObj.flagNoData:
73 return 0
74
75 if self.tauList == None: # se lee el tauList desde el archivo
76 flip = None
77 if self.dataInObj.m_RadarControllerHeader.flip1 != None:
78 flip = self.dataInObj.m_RadarControllerHeader.flip1
79
80 if self.dataInObj.m_RadarControllerHeader.flip2 != None:
81 flip = self.dataInObj.m_RadarControllerHeader.flip2
82
83 if flip == None:
84 flip = 2
85 print 'flip is None --> flip = %d '%flip
86
87 ntaus = self.dataInObj.m_RadarControllerHeader.numTaus
88 taus = self.dataInObj.m_RadarControllerHeader.Taus.reshape(ntaus/flip,flip)
89
90 index = 0
91 self.tauList = taus[:,index]
92 print 'tauList is None --> tauList = obj.m_RadarControllerHeader.Taus[:,%d]'%index
93
94 self.nLags = len(self.tauList)
95
96 if self.pairList == None:
97 self.pairList = [(0,0)] # por defecto calcula la AutoCorrelacion de una canal
98
99 self.dataOutObj.tauList = self.tauList
100 self.dataOutObj.nLags = self.nLags
101 self.dataOutObj.pairList = self.pairList
102
103 if self.buffer == None:
104 nhei = self.dataInObj.nHeights
105 npairList = len(self.pairList)
106 self.buffer = numpy.zeros((self.nLags,nhei,npairList),dtype='complex')
107
108 bufferZ = numpy.zeros((npairList,self.dataInObj.nHeights),dtype='complex')
109
110 indexHeight = self.tauList[self.indexTau] / self.dataInObj.m_ProcessingHeader.deltaHeight
111
112 countPair = 0
113
114 # make (signalA*signalB'), where signalA: channel without delay, signalB: channel with delay,
115 for pair in self.pairList:
116 bufferZ[countPair,0:self.dataInObj.nHeights-indexHeight] = self.dataInObj.data[pair[1],indexHeight:self.dataInObj.nHeights]
117 signalA = self.dataInObj.data[pair[0],:]
118 signalB = bufferZ[countPair,:]
119 data = signalA * numpy.conjugate(signalB)
120 self.buffer[self.indexTau,:,countPair] = data
121 countPair += 1
122
123 # change index Tau and lagCounter
124 self.indexTau += 1
125 if self.indexTau >= self.nLags:
126 self.indexTau = 0
127 self.dataOutObj.data = self.buffer
128 self.buffer = None
129 self.dataOutObj.flagNoData = False
130 else:
131 self.dataOutObj.flagNoData = True
132
20
133
21 m_Voltage= Voltage()
134 def addIntegrator(self):
135 pass
136
137 def addWriter(self):
138 pass
139
140 def addPlotter(self):
141 pass
142
143 class Integrator():
144 def __init__(self):
145 pass
22
146
@@ -28,6 +28,7 class VoltageProcessor:
28 profSelectorObjIndex = None
28 profSelectorObjIndex = None
29 writerObjIndex = None
29 writerObjIndex = None
30 plotterObjIndex = None
30 plotterObjIndex = None
31 flipIndex = None
31
32
32 integratorObjList = []
33 integratorObjList = []
33 decoderObjList = []
34 decoderObjList = []
@@ -60,7 +61,7 class VoltageProcessor:
60 self.profSelectorObjIndex = None
61 self.profSelectorObjIndex = None
61 self.writerObjIndex = None
62 self.writerObjIndex = None
62 self.plotterObjIndex = None
63 self.plotterObjIndex = None
63
64 self.flipIndex = 1
64 self.integratorObjList = []
65 self.integratorObjList = []
65 self.decoderObjList = []
66 self.decoderObjList = []
66 self.profileSelectorObjList = []
67 self.profileSelectorObjList = []
@@ -75,6 +76,10 class VoltageProcessor:
75 self.writerObjIndex = 0
76 self.writerObjIndex = 0
76 self.plotterObjIndex = 0
77 self.plotterObjIndex = 0
77 self.dataOutObj.copy(self.dataInObj)
78 self.dataOutObj.copy(self.dataInObj)
79
80 if self.profSelectorObjIndex != None:
81 for profSelObj in self.profileSelectorObjList:
82 profSelObj.incIndex()
78
83
79 def addWriter(self, wrpath):
84 def addWriter(self, wrpath):
80 objWriter = VoltageWriter(self.dataOutObj)
85 objWriter = VoltageWriter(self.dataOutObj)
@@ -173,8 +178,30 class VoltageProcessor:
173
178
174
179
175 def filterByHei(self, window):
180 def filterByHei(self, window):
176 pass
181 if window == None:
177
182 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
183
184 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
185 dim1 = self.dataOutObj.data.shape[0]
186 dim2 = self.dataOutObj.data.shape[1]
187 r = dim2 % window
188
189 buffer = self.dataOutObj.data[:,0:dim2-r]
190 buffer = buffer.reshape(dim1,dim2/window,window)
191 buffer = numpy.sum(buffer,2)
192 self.dataOutObj.data = buffer
193
194 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
195 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
196
197 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
198
199 #self.dataOutObj.heightList es un numpy.array
200 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
201
202 def deFlip(self):
203 self.dataOutObj.data *= self.flipIndex
204 self.flipIndex *= -1.
178
205
179 def selectChannels(self, channelList):
206 def selectChannels(self, channelList):
180 """
207 """
@@ -310,8 +337,27 class VoltageProcessor:
310 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
337 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
311 return 1
338 return 1
312
339
340 def selectProfilesByValue(self,indexList, nProfiles):
341 if self.dataOutObj.flagNoData:
342 return 0
343
344 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
345 self.addProfileSelector(nProfiles)
346
347 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
348
349 if not(profileSelectorObj.isProfileInList(indexList)):
350 self.dataOutObj.flagNoData = True
351 self.profSelectorObjIndex += 1
352 return 0
353
354 self.dataOutObj.flagNoData = False
355 self.profSelectorObjIndex += 1
356
357 return 1
358
313
359
314 def selectProfiles(self, minIndex, maxIndex, nProfiles):
360 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
315 """
361 """
316 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
362 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
317 minIndex <= index <= maxIndex
363 minIndex <= index <= maxIndex
@@ -337,15 +383,15 class VoltageProcessor:
337
383
338 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
384 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
339
385
340 if profileSelectorObj.isProfileInRange(minIndex, maxIndex):
386 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
341 self.dataOutObj.flagNoData = False
387 self.dataOutObj.flagNoData = True
342 self.profSelectorObjIndex += 1
388 self.profSelectorObjIndex += 1
343 return 1
389 return 0
344
390
345 self.dataOutObj.flagNoData = True
391 self.dataOutObj.flagNoData = False
346 self.profSelectorObjIndex += 1
392 self.profSelectorObjIndex += 1
347
393
348 return 0
394 return 1
349
395
350 def selectNtxs(self, ntx):
396 def selectNtxs(self, ntx):
351 pass
397 pass
@@ -466,37 +512,36 class CoherentIntegrator:
466
512
467 class ProfileSelector:
513 class ProfileSelector:
468
514
469 indexProfile = None
515 profileIndex = None
470 # Tamanho total de los perfiles
516 # Tamanho total de los perfiles
471 nProfiles = None
517 nProfiles = None
472
518
473 def __init__(self, nProfiles):
519 def __init__(self, nProfiles):
474
520
475 self.indexProfile = 0
521 self.profileIndex = 0
476 self.nProfiles = nProfiles
522 self.nProfiles = nProfiles
477
523
524 def incIndex(self):
525 self.profileIndex += 1
526
527 if self.profileIndex >= self.nProfiles:
528 self.profileIndex = 0
529
478 def isProfileInRange(self, minIndex, maxIndex):
530 def isProfileInRange(self, minIndex, maxIndex):
479
531
480 if self.indexProfile < minIndex:
532 if self.profileIndex < minIndex:
481 self.indexProfile += 1
482 return False
533 return False
483
534
484 if self.indexProfile > maxIndex:
535 if self.profileIndex > maxIndex:
485 self.indexProfile += 1
486 return False
536 return False
487
537
488 self.indexProfile += 1
489
490 return True
538 return True
491
539
492 def isProfileInList(self, profileList):
540 def isProfileInList(self, profileList):
493
541
494 if self.indexProfile not in profileList:
542 if self.profileIndex not in profileList:
495 self.indexProfile += 1
496 return False
543 return False
497
544
498 self.indexProfile += 1
499
500 return True
545 return True
501
546
502
547
General Comments 0
You need to be logged in to leave comments. Login now