##// END OF EJS Templates
Reading and doing Operation in Blocks to processing radar data from MST_ISR_EEJ Experiment
Daniel Valdez -
r495:4f47402d085c
parent child
Show More
@@ -0,0 +1,217
1 import os, sys
2 import timeit
3
4 path = os.path.split(os.getcwd())[0]
5 sys.path.append(path)
6
7 from controller import *
8
9 desc = "MST-ISR-EEJ Experiment Test"
10 filename = "mst_isr_eej_blocks.xml"
11
12 controllerObj = Project()
13
14 controllerObj.setup(id = '191', name='test01', description=desc)
15
16 path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift'
17
18 path = '/media/administrator/New Volume/DATA/MST_ISR'
19
20 path = '/home/administrator/Documents/mst_isr_eej'
21
22 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
23 path=path,
24 startDate='2014/01/09',
25 endDate='2014/01/09',
26 startTime='00:00:00',
27 endTime='23:59:59',
28 online=0,
29 delay=10,
30 walk=0,
31 getblock=1)
32
33 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
34 # ################ EEJ ####################################
35 procUnitConfObjEEJ = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
36
37 opObj11 = procUnitConfObjEEJ.addOperation(name='ProfileSelector', optype='other')
38 opObj11.addParameter(name='profileRangeList', value='120,183', format='intlist')
39 opObj11.addParameter(name='byblock', value='1', format='bool')
40
41 opObj11 = procUnitConfObjEEJ.addOperation(name='Decoder', optype='other')
42 opObj11.addParameter(name='code', value='1,-1', format='floatlist')
43 opObj11.addParameter(name='nCode', value='2', format='int')
44 opObj11.addParameter(name='nBaud', value='1', format='int')
45 opObj11.addParameter(name='mode', value='3', format='int')
46 opObj11.addParameter(name='times', value='32', format='int')
47
48 # opObj11 = procUnitConfObjEEJ.addOperation(name='CohInt', optype='other')
49 # opObj11.addParameter(name='n', value='2', format='int')
50
51 procUnitConfObjEEJSpecta = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjEEJ.getId())
52 procUnitConfObjEEJSpecta.addParameter(name='nFFTPoints', value='64', format='int')
53 procUnitConfObjEEJSpecta.addParameter(name='nProfiles', value='64', format='int')
54
55 opObj11 = procUnitConfObjEEJSpecta.addOperation(name='IncohInt', optype='other')
56 #opObj11.addParameter(name='timeInterval', value='10', format='float')
57 opObj11.addParameter(name='n', value='36', format='float')
58
59 opObj11 = procUnitConfObjEEJSpecta.addOperation(name='SpectraPlot', optype='other')
60 opObj11.addParameter(name='id', value='100', format='int')
61 opObj11.addParameter(name='wintitle', value='EEJ', format='str')
62 # opObj11.addParameter(name='zmin', value='20', format='int')
63 # opObj11.addParameter(name='zmax', value='60', format='int')# opObj11.addParameter(name='ftp', value='1', format='int')
64 # opObj11.addParameter(name='save', value='1', format='int')
65 # opObj11.addParameter(name='figpath', value='/home/operaciones/Pictures/MST-ISR', format='str')
66 # opObj11.addParameter(name='wr_period', value='15', format='int')
67 # opObj11.addParameter(name='ftp', value='1', format='int')
68 # opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str')
69 # opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str')
70 # opObj11.addParameter(name='username', value='wmaster', format='str')
71 # opObj11.addParameter(name='password', value='mst2010vhf', format='str')
72 # opObj11.addParameter(name='ftp_wei', value='0', format='int')
73 # opObj11.addParameter(name='exp_code', value='22', format='int')
74 # opObj11.addParameter(name='sub_exp_code', value='0', format='int')
75 # opObj11.addParameter(name='plot_pos', value='0', format='int')
76
77
78 # opObj11 = procUnitConfObjEEJSpecta.addOperation(name='RTIPlot', optype='other')
79 # opObj11.addParameter(name='id', value='101', format='int')
80 # opObj11.addParameter(name='wintitle', value='EEJ', format='str')
81 # opObj11.addParameter(name='showprofile', value='0', format='int')
82 # opObj11.addParameter(name='xmin', value='0', format='int')
83 # opObj11.addParameter(name='xmax', value='24', format='int')
84 # opObj11.addParameter(name='save', value='1', format='int')
85 # opObj11.addParameter(name='figpath', value='/home/operaciones/Pictures/MST-ISR', format='str')
86 # opObj11.addParameter(name='wr_period', value='15', format='int')
87 # opObj11.addParameter(name='ftp', value='1', format='int')
88 # opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str')
89 # opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str')
90 # opObj11.addParameter(name='username', value='wmaster', format='str')
91 # opObj11.addParameter(name='password', value='mst2010vhf', format='str')
92 # opObj11.addParameter(name='ftp_wei', value='0', format='int')
93 # opObj11.addParameter(name='exp_code', value='22', format='int')
94 # opObj11.addParameter(name='sub_exp_code', value='0', format='int')
95 # opObj11.addParameter(name='plot_pos', value='0', format='int')
96
97 ################ MST ####################################
98 procUnitConfObjMST = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
99
100 opObj11 = procUnitConfObjMST.addOperation(name='ProfileSelector', optype='other')
101 profileIndex = '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119'
102 #profileIndex = '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19'
103 opObj11.addParameter(name='profileList', value=profileIndex, format='intlist')
104 opObj11.addParameter(name='byblock', value='1', format='bool')
105
106 opObj11 = procUnitConfObjMST.addOperation(name='Decoder', optype='other')
107 opObj11.addParameter(name='mode',value='3',format='int')
108 opObj11.addParameter(name='times',value='10',format='int')
109
110 opObj11 = procUnitConfObjMST.addOperation(name='CohInt', optype='other')
111 opObj11.addParameter(name='n', value='20', format='int')
112 opObj11.addParameter(name='byblock', value='1', format='bool')
113
114 procUnitConfObjMSTSpectra = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjMST.getId())
115 procUnitConfObjMSTSpectra.addParameter(name='nFFTPoints', value='64', format='int')
116 procUnitConfObjMSTSpectra.addParameter(name='nProfiles', value='64', format='int')
117
118 opObj11 = procUnitConfObjMSTSpectra.addOperation(name='IncohInt', optype='other')
119 opObj11.addParameter(name='n', value='2', format='float')
120
121 opObj11 = procUnitConfObjMSTSpectra.addOperation(name='SpectraPlot', optype='other')
122 opObj11.addParameter(name='id', value='200', format='int')
123 opObj11.addParameter(name='wintitle', value='MST', format='str')
124 # opObj11.addParameter(name='zmin', value='35', format='int')
125 # opObj11.addParameter(name='zmax', value='60', format='int')
126 # opObj11.addParameter(name='save', value='1', format='int')
127 # opObj11.addParameter(name='figpath', value='/home/operaciones/Pictures/MST-ISR', format='str')
128 # opObj11.addParameter(name='wr_period', value='5', format='int')
129 # opObj11.addParameter(name='ftp', value='1', format='int')
130 # opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str')
131 # opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str')
132 # opObj11.addParameter(name='username', value='wmaster', format='str')
133 # opObj11.addParameter(name='password', value='mst2010vhf', format='str')
134 # opObj11.addParameter(name='ftp_wei', value='0', format='int')
135 # opObj11.addParameter(name='exp_code', value='19', format='int')
136 # opObj11.addParameter(name='sub_exp_code', value='0', format='int')
137 # opObj11.addParameter(name='plot_pos', value='0', format='int')
138 #
139 # opObj11 = procUnitConfObjMSTSpectra.addOperation(name='RTIPlot', optype='other')
140 # opObj11.addParameter(name='id', value='201', format='int')
141 # opObj11.addParameter(name='wintitle', value='MST', format='str')
142 # opObj11.addParameter(name='showprofile', value='0', format='int')
143 # opObj11.addParameter(name='xmin', value='0', format='int')
144 # opObj11.addParameter(name='xmax', value='24', format='int')
145 # opObj11.addParameter(name='zmin', value='35', format='int')
146 # opObj11.addParameter(name='zmax', value='60', format='int')
147 # opObj11.addParameter(name='save', value='1', format='int')
148 # opObj11.addParameter(name='figpath', value='/home/operaciones/Pictures/MST-ISR', format='str')
149 # opObj11.addParameter(name='wr_period', value='5', format='int')
150 # opObj11.addParameter(name='ftp', value='1', format='int')
151 # opObj11.addParameter(name='server', value='jro-app.igp.gob.pe', format='str')
152 # opObj11.addParameter(name='folder', value='/home/wmaster/graficos', format='str')
153 # opObj11.addParameter(name='username', value='wmaster', format='str')
154 # opObj11.addParameter(name='password', value='mst2010vhf', format='str')
155 # opObj11.addParameter(name='ftp_wei', value='0', format='int')
156 # opObj11.addParameter(name='exp_code', value='19', format='int')
157 # opObj11.addParameter(name='sub_exp_code', value='0', format='int')
158 # opObj11.addParameter(name='plot_pos', value='0', format='int')
159
160 # ################ ISR ####################################
161 procUnitConfObjISR = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
162
163 opObj11 = procUnitConfObjISR.addOperation(name='ProfileSelector', optype='other')
164 # profileIndex = '20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99'
165 # opObj11.addParameter(name='profileList', value=profileIndex, format='intlist')
166 opObj11.addParameter(name='profileRangeList', value='20,99', format='intlist')
167 opObj11.addParameter(name='byblock', value='1', format='bool')
168
169 # opObj11 = procUnitConfObjISR.addOperation(name='ProfileConcat', optype='other')
170 # opObj11.addParameter(name='m', value='5', format='int')
171
172 opObj11 = procUnitConfObjISR.addOperation(name='Reshaper', optype='other') #Esta Operacion opera sobre bloques y reemplaza el ProfileConcat que opera sobre perfiles
173 opObj11.addParameter(name='shape', value='4,16,6750', format='intlist')
174
175 opObj11 = procUnitConfObjISR.addOperation(name='filterByHeights')
176 opObj11.addParameter(name='window', value='20', format='int')
177 opObj11.addParameter(name='axis', value='2', format='int')
178
179 barker3x1 = '1,1,-1,-1,-1,1'
180 #barker3x5 = '1,1,1,1,1, 1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1'
181
182 opObj11 = procUnitConfObjISR.addOperation(name='Decoder', optype='other')
183 opObj11.addParameter(name='code', value=barker3x1, format='floatlist')
184 opObj11.addParameter(name='nCode', value='2', format='int')
185 #opObj11.addParameter(name='nBaud', value='15', format='int')
186 opObj11.addParameter(name='nBaud', value='3', format='int')
187 opObj11.addParameter(name='mode', value='3', format='int')
188 opObj11.addParameter(name='times', value='8', format='int')
189 opObj11.addParameter(name='osamp', value='5', format='int')
190
191
192 procUnitConfObjISRSpectra = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObjISR.getId())
193 procUnitConfObjISRSpectra.addParameter(name='nFFTPoints', value='16', format='int')
194 procUnitConfObjISRSpectra.addParameter(name='nProfiles', value='16', format='int')
195
196 opObj11 = procUnitConfObjISRSpectra.addOperation(name='IncohInt', optype='other')
197 opObj11.addParameter(name='n', value='36', format='float')
198
199 opObj11 = procUnitConfObjISRSpectra.addOperation(name='SpectraPlot', optype='other')
200 opObj11.addParameter(name='id', value='300', format='int')
201 opObj11.addParameter(name='wintitle', value='ISR', format='str')
202 # opObj11.addParameter(name='save', value='1', format='bool')
203 # opObj11.addParameter(name='figpath', value='/home/administrator/Pictures/mst_isr_eej', format='str')
204
205
206 print "Escribiendo el archivo XML"
207 controllerObj.writeXml(filename)
208 print "Leyendo el archivo XML"
209 controllerObj.readXml(filename)
210
211 controllerObj.createObjects()
212 controllerObj.connectObjects()
213
214 #timeit.timeit('controllerObj.run()', number=2)
215
216 controllerObj.run()
217 #print fib(5) No newline at end of file
@@ -344,6 +344,8 class JRODataIO:
344
344
345 blocksize = None
345 blocksize = None
346
346
347 getblock = False
348
347 def __init__(self):
349 def __init__(self):
348
350
349 raise ValueError, "Not implemented"
351 raise ValueError, "Not implemented"
@@ -934,7 +936,8 class JRODataReader(JRODataIO):
934 ext = None,
936 ext = None,
935 online = False,
937 online = False,
936 delay = 60,
938 delay = 60,
937 walk = True):
939 walk = True,
940 getblock = False):
938
941
939 if path == None:
942 if path == None:
940 raise ValueError, "The path is not valid"
943 raise ValueError, "The path is not valid"
@@ -991,7 +994,7 class JRODataReader(JRODataIO):
991 self.delay = delay
994 self.delay = delay
992 ext = ext.lower()
995 ext = ext.lower()
993 self.ext = ext
996 self.ext = ext
994
997 self.getblock = getblock
995 if not(self.setNextFile()):
998 if not(self.setNextFile()):
996 if (startDate!=None) and (endDate!=None):
999 if (startDate!=None) and (endDate!=None):
997 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
1000 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
@@ -309,13 +309,18 class VoltageReader(JRODataReader, ProcessingUnit):
309 self.dataOut.flagNoData = True
309 self.dataOut.flagNoData = True
310 return 0
310 return 0
311
311
312 self.dataOut.data = self.datablock[:,self.profileIndex,:]
312 if self.getblock:
313 self.dataOut.data = self.datablock
314 self.profileIndex = self.processingHeaderObj.profilesPerBlock
315 else:
316 self.dataOut.data = self.datablock[:,self.profileIndex,:]
317 self.profileIndex += 1
313
318
314 self.dataOut.flagNoData = False
319 self.dataOut.flagNoData = False
315
320
316 self.getBasicHeader()
321 self.getBasicHeader()
317
322
318 self.profileIndex += 1
323
319
324
320 self.dataOut.realtime = self.online
325 self.dataOut.realtime = self.online
321
326
@@ -14,6 +14,8 class SpectraProc(ProcessingUnit):
14 self.firstdatatime = None
14 self.firstdatatime = None
15 self.profIndex = 0
15 self.profIndex = 0
16 self.dataOut = Spectra()
16 self.dataOut = Spectra()
17 self.id_min = None
18 self.id_max = None
17
19
18 def __updateObjFromInput(self):
20 def __updateObjFromInput(self):
19
21
@@ -103,12 +105,9 class SpectraProc(ProcessingUnit):
103 if nFFTPoints == None:
105 if nFFTPoints == None:
104 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
106 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
105
107
106 nProfiles = nFFTPoints
108 if nProfiles == None:
107
109 raise ValueError, "This SpectraProc.run() need nProfiles input variable"
108 # if pairsList == None:
110
109 # nPairs = 0
110 # else:
111 # nPairs = len(pairsList)
112
111
113 if ippFactor == None:
112 if ippFactor == None:
114 ippFactor = 1
113 ippFactor = 1
@@ -116,17 +115,32 class SpectraProc(ProcessingUnit):
116
115
117 self.dataOut.nFFTPoints = nFFTPoints
116 self.dataOut.nFFTPoints = nFFTPoints
118 self.dataOut.pairsList = pairsList
117 self.dataOut.pairsList = pairsList
119 # self.dataOut.nPairs = nPairs
118
120
121 if self.buffer == None:
119 if self.buffer == None:
122 self.buffer = numpy.zeros((self.dataIn.nChannels,
120 self.buffer = numpy.zeros((self.dataIn.nChannels,
123 nProfiles,
121 nProfiles,
124 self.dataIn.nHeights),
122 self.dataIn.nHeights),
125 dtype='complex')
123 dtype='complex')
124 self.id_min = 0
125 self.id_max = self.dataIn.data.shape[1]
126
126
127
127 if len(self.dataIn.data.shape) == 2:
128 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
128 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
129 self.profIndex += 1
129 self.profIndex += 1
130 else:
131 if self.dataIn.data.shape[1] == nProfiles:
132 self.buffer = self.dataIn.data.copy()
133 self.profIndex = nProfiles
134 elif self.dataIn.data.shape[1] < nProfiles:
135 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
136 self.profIndex += self.dataIn.data.shape[1]
137 self.id_min += self.dataIn.data.shape[1]
138 self.id_max += self.dataIn.data.shape[1]
139 else:
140 raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
141 self.dataOut.flagNoData = True
142 return 0
143
130
144
131 if self.firstdatatime == None:
145 if self.firstdatatime == None:
132 self.firstdatatime = self.dataIn.utctime
146 self.firstdatatime = self.dataIn.utctime
@@ -911,115 +925,3 class IncohInt(Operation):
911 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
925 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
912 dataOut.timeInterval = self.__timeInterval*self.n
926 dataOut.timeInterval = self.__timeInterval*self.n
913 dataOut.flagNoData = False
927 dataOut.flagNoData = False
914
915 class ProfileConcat(Operation):
916
917 isConfig = False
918 buffer = None
919
920 def __init__(self):
921
922 Operation.__init__(self)
923 self.profileIndex = 0
924
925 def reset(self):
926 self.buffer = numpy.zeros_like(self.buffer)
927 self.start_index = 0
928 self.times = 1
929
930 def setup(self, data, m, n=1):
931 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
932 self.profiles = data.shape[1]
933 self.start_index = 0
934 self.times = 1
935
936 def concat(self, data):
937
938 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
939 self.start_index = self.start_index + self.profiles
940
941 def run(self, dataOut, m):
942
943 dataOut.flagNoData = True
944
945 if not self.isConfig:
946 self.setup(dataOut.data, m, 1)
947 self.isConfig = True
948
949 self.concat(dataOut.data)
950 self.times += 1
951 if self.times > m:
952 dataOut.data = self.buffer
953 self.reset()
954 dataOut.flagNoData = False
955 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
956 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
957 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5
958 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
959
960 class ProfileSelector(Operation):
961
962 profileIndex = None
963 # Tamanho total de los perfiles
964 nProfiles = None
965
966 def __init__(self):
967
968 Operation.__init__(self)
969 self.profileIndex = 0
970
971 def incIndex(self):
972 self.profileIndex += 1
973
974 if self.profileIndex >= self.nProfiles:
975 self.profileIndex = 0
976
977 def isProfileInRange(self, minIndex, maxIndex):
978
979 if self.profileIndex < minIndex:
980 return False
981
982 if self.profileIndex > maxIndex:
983 return False
984
985 return True
986
987 def isProfileInList(self, profileList):
988
989 if self.profileIndex not in profileList:
990 return False
991
992 return True
993
994 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None):
995
996 dataOut.flagNoData = True
997 self.nProfiles = dataOut.nProfiles
998
999 if profileList != None:
1000 if self.isProfileInList(profileList):
1001 dataOut.flagNoData = False
1002
1003 self.incIndex()
1004 return 1
1005
1006
1007 elif profileRangeList != None:
1008 minIndex = profileRangeList[0]
1009 maxIndex = profileRangeList[1]
1010 if self.isProfileInRange(minIndex, maxIndex):
1011 dataOut.flagNoData = False
1012
1013 self.incIndex()
1014 return 1
1015 elif beam != None:
1016 if self.isProfileInList(dataOut.beamRangeDict[beam]):
1017 dataOut.flagNoData = False
1018
1019 self.incIndex()
1020 return 1
1021
1022 else:
1023 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1024
1025 return 0
@@ -188,21 +188,33 class VoltageProc(ProcessingUnit):
188 return 1
188 return 1
189
189
190
190
191 def filterByHeights(self, window):
191 def filterByHeights(self, window, axis=1):
192 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
192 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
193
193
194 if window == None:
194 if window == None:
195 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
195 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
196
196
197 newdelta = deltaHeight * window
197 newdelta = deltaHeight * window
198 r = self.dataOut.data.shape[1] % window
198 r = self.dataOut.data.shape[axis] % window
199 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
199 if axis == 1:
200 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
200 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[axis]-r]
201 buffer = numpy.sum(buffer,2)
201 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[axis]/window,window)
202 self.dataOut.data = buffer
202 buffer = numpy.sum(buffer,axis+1)
203
204 elif axis == 2:
205 buffer = self.dataOut.data[:, :, 0:self.dataOut.data.shape[axis]-r]
206 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1],self.dataOut.data.shape[axis]/window,window)
207 buffer = numpy.sum(buffer,axis+1)
208
209 else:
210 raise ValueError, "axis value should be 1 or 2, the input value %d is not valid" % (axis)
211
212 self.dataOut.data = buffer.copy()
203 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
213 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
204 self.dataOut.windowOfFilter = window
214 self.dataOut.windowOfFilter = window
205
215
216 return 1
217
206 def deFlip(self):
218 def deFlip(self):
207 self.dataOut.data *= self.flip
219 self.dataOut.data *= self.flip
208 self.flip *= -1.
220 self.flip *= -1.
@@ -238,7 +250,7 class CohInt(Operation):
238
250
239 # self.isConfig = False
251 # self.isConfig = False
240
252
241 def setup(self, n=None, timeInterval=None, overlapping=False):
253 def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False):
242 """
254 """
243 Set the parameters of the integration class.
255 Set the parameters of the integration class.
244
256
@@ -254,7 +266,7 class CohInt(Operation):
254 self.__lastdatatime = 0
266 self.__lastdatatime = 0
255 self.__buffer = None
267 self.__buffer = None
256 self.__dataReady = False
268 self.__dataReady = False
257
269 self.byblock = byblock
258
270
259 if n == None and timeInterval == None:
271 if n == None and timeInterval == None:
260 raise ValueError, "n or timeInterval should be specified ..."
272 raise ValueError, "n or timeInterval should be specified ..."
@@ -392,14 +404,35 class CohInt(Operation):
392 self.__initime += deltatime
404 self.__initime += deltatime
393
405
394 return avgdata, avgdatatime
406 return avgdata, avgdatatime
395
407
408 def integrateByBlock(self, dataOut):
409 times = int(dataOut.data.shape[1]/self.n)
410 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
411
412 id_min = 0
413 id_max = self.n
414
415 for i in range(times):
416 junk = dataOut.data[:,id_min:id_max,:]
417 avgdata[:,i,:] = junk.sum(axis=1)
418 id_min += self.n
419 id_max += self.n
420
421 timeInterval = dataOut.ippSeconds*self.n
422 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
423 self.__dataReady = True
424 return avgdata, avgdatatime
425
396 def run(self, dataOut, **kwargs):
426 def run(self, dataOut, **kwargs):
397
427
398 if not self.isConfig:
428 if not self.isConfig:
399 self.setup(**kwargs)
429 self.setup(**kwargs)
400 self.isConfig = True
430 self.isConfig = True
401
431
402 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
432 if self.byblock:
433 avgdata, avgdatatime = self.integrateByBlock(dataOut)
434 else:
435 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
403
436
404 # dataOut.timeInterval *= n
437 # dataOut.timeInterval *= n
405 dataOut.flagNoData = True
438 dataOut.flagNoData = True
@@ -421,12 +454,17 class Decoder(Operation):
421 nCode = None
454 nCode = None
422 nBaud = None
455 nBaud = None
423
456
457
424 def __init__(self):
458 def __init__(self):
425
459
426 Operation.__init__(self)
460 Operation.__init__(self)
461
462 self.times = None
463 self.osamp = None
464 self.__setValues = False
427 # self.isConfig = False
465 # self.isConfig = False
428
466
429 def setup(self, code, shape):
467 def setup(self, code, shape, times, osamp):
430
468
431 self.__profIndex = 0
469 self.__profIndex = 0
432
470
@@ -435,17 +473,34 class Decoder(Operation):
435 self.nCode = len(code)
473 self.nCode = len(code)
436 self.nBaud = len(code[0])
474 self.nBaud = len(code[0])
437
475
438 self.__nChannels, self.__nHeis = shape
476 if times != None:
477 self.times = times
439
478
440 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
479 if ((osamp != None) and (osamp >1)):
480 self.osamp = osamp
481 self.code = numpy.repeat(code, repeats=self.osamp,axis=1)
482 self.nBaud = self.nBaud*self.osamp
441
483
442 __codeBuffer[:,0:self.nBaud] = self.code
484 if len(shape) == 2:
443
485 self.__nChannels, self.__nHeis = shape
444 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
486
445
487 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
446 self.ndatadec = self.__nHeis - self.nBaud + 1
488
489 __codeBuffer[:,0:self.nBaud] = self.code
490
491 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
492
493 self.ndatadec = self.__nHeis - self.nBaud + 1
494
495 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
496 else:
497 self.__nChannels, self.__nProfiles, self.__nHeis = shape
498
499 self.ndatadec = self.__nHeis - self.nBaud + 1
500
501 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
447
502
448 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
503
449
504
450 def convolutionInFreq(self, data):
505 def convolutionInFreq(self, data):
451
506
@@ -480,12 +535,30 class Decoder(Operation):
480
535
481 return self.datadecTime
536 return self.datadecTime
482
537
483 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
538 def convolutionByBlockInTime(self, data):
539 junk = numpy.lib.stride_tricks.as_strided(self.code, (self.times, self.code.size), (0, self.code.itemsize))
540 junk = junk.flatten()
541 code_block = numpy.reshape(junk, (self.nCode*self.times,self.nBaud))
542
543 for i in range(self.__nChannels):
544 for j in range(self.__nProfiles):
545 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='valid')
546
547 return self.datadecTime
548
549 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None):
484
550
485 if code == None:
551 if code == None:
486 code = dataOut.code
552 code = dataOut.code
487 else:
553 else:
488 code = numpy.array(code).reshape(nCode,nBaud)
554 code = numpy.array(code).reshape(nCode,nBaud)
555
556
557
558 if not self.isConfig:
559
560 self.setup(code, dataOut.data.shape, times, osamp)
561
489 dataOut.code = code
562 dataOut.code = code
490 dataOut.nCode = nCode
563 dataOut.nCode = nCode
491 dataOut.nBaud = nBaud
564 dataOut.nBaud = nBaud
@@ -493,10 +566,6 class Decoder(Operation):
493 dataOut.radarControllerHeaderObj.nCode = nCode
566 dataOut.radarControllerHeaderObj.nCode = nCode
494 dataOut.radarControllerHeaderObj.nBaud = nBaud
567 dataOut.radarControllerHeaderObj.nBaud = nBaud
495
568
496
497 if not self.isConfig:
498
499 self.setup(code, dataOut.data.shape)
500 self.isConfig = True
569 self.isConfig = True
501
570
502 if mode == 0:
571 if mode == 0:
@@ -507,6 +576,18 class Decoder(Operation):
507
576
508 if mode == 2:
577 if mode == 2:
509 datadec = self.convolutionInFreqOpt(dataOut.data)
578 datadec = self.convolutionInFreqOpt(dataOut.data)
579
580 if mode == 3:
581 datadec = self.convolutionByBlockInTime(dataOut.data)
582
583 if not(self.__setValues):
584 dataOut.code = self.code
585 dataOut.nCode = self.nCode
586 dataOut.nBaud = self.nBaud
587 dataOut.radarControllerHeaderObj.code = self.code
588 dataOut.radarControllerHeaderObj.nCode = self.nCode
589 dataOut.radarControllerHeaderObj.nBaud = self.nBaud
590 self.__setValues = True
510
591
511 dataOut.data = datadec
592 dataOut.data = datadec
512
593
@@ -522,3 +603,149 class Decoder(Operation):
522
603
523 return 1
604 return 1
524 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
605 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
606
607
608 class ProfileConcat(Operation):
609
610 isConfig = False
611 buffer = None
612
613 def __init__(self):
614
615 Operation.__init__(self)
616 self.profileIndex = 0
617
618 def reset(self):
619 self.buffer = numpy.zeros_like(self.buffer)
620 self.start_index = 0
621 self.times = 1
622
623 def setup(self, data, m, n=1):
624 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
625 self.profiles = data.shape[1]
626 self.start_index = 0
627 self.times = 1
628
629 def concat(self, data):
630
631 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
632 self.start_index = self.start_index + self.profiles
633
634 def run(self, dataOut, m):
635
636 dataOut.flagNoData = True
637
638 if not self.isConfig:
639 self.setup(dataOut.data, m, 1)
640 self.isConfig = True
641
642 self.concat(dataOut.data)
643 self.times += 1
644 if self.times > m:
645 dataOut.data = self.buffer
646 self.reset()
647 dataOut.flagNoData = False
648 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
649 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
650 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5
651 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
652
653 class ProfileSelector(Operation):
654
655 profileIndex = None
656 # Tamanho total de los perfiles
657 nProfiles = None
658
659 def __init__(self):
660
661 Operation.__init__(self)
662 self.profileIndex = 0
663
664 def incIndex(self):
665 self.profileIndex += 1
666
667 if self.profileIndex >= self.nProfiles:
668 self.profileIndex = 0
669
670 def isProfileInRange(self, minIndex, maxIndex):
671
672 if self.profileIndex < minIndex:
673 return False
674
675 if self.profileIndex > maxIndex:
676 return False
677
678 return True
679
680 def isProfileInList(self, profileList):
681
682 if self.profileIndex not in profileList:
683 return False
684
685 return True
686
687 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False):
688
689 dataOut.flagNoData = True
690 self.nProfiles = dataOut.nProfiles
691
692 if byblock:
693
694 if profileList != None:
695 dataOut.data = dataOut.data[:,profileList,:]
696 pass
697 else:
698 pmin = profileRangeList[0]
699 pmax = profileRangeList[1]
700 dataOut.data = dataOut.data[:,pmin:pmax+1,:]
701 dataOut.flagNoData = False
702 self.profileIndex = 0
703 return 1
704
705 if profileList != None:
706 if self.isProfileInList(profileList):
707 dataOut.flagNoData = False
708
709 self.incIndex()
710 return 1
711
712
713 elif profileRangeList != None:
714 minIndex = profileRangeList[0]
715 maxIndex = profileRangeList[1]
716 if self.isProfileInRange(minIndex, maxIndex):
717 dataOut.flagNoData = False
718
719 self.incIndex()
720 return 1
721 elif beam != None: #beam is only for AMISR data
722 if self.isProfileInList(dataOut.beamRangeDict[beam]):
723 dataOut.flagNoData = False
724
725 self.incIndex()
726 return 1
727
728 else:
729 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
730
731 return 0
732
733
734
735 class Reshaper(Operation):
736 def __init__(self):
737 Operation.__init__(self)
738 self.updateNewHeights = False
739
740 def run(self, dataOut, shape):
741 shape_tuple = tuple(shape)
742 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
743 dataOut.flagNoData = False
744
745 if not(self.updateNewHeights):
746 old_nheights = dataOut.nHeights
747 new_nheights = dataOut.data.shape[2]
748 factor = new_nheights / old_nheights
749 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
750 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor
751 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now