@@ -1,678 +1,686 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: Daniel Suarez |
|
2 | @author: Daniel Suarez | |
3 | ''' |
|
3 | ''' | |
4 |
|
4 | |||
5 | import os |
|
5 | import os | |
6 | import sys |
|
6 | import sys | |
7 | import glob |
|
7 | import glob | |
8 | import fnmatch |
|
8 | import fnmatch | |
9 | import datetime |
|
9 | import datetime | |
10 | import time |
|
10 | import time | |
11 | import re |
|
11 | import re | |
12 | import h5py |
|
12 | import h5py | |
13 | import numpy |
|
13 | import numpy | |
14 |
|
14 | |||
15 | from model.proc.jroproc_base import ProcessingUnit, Operation |
|
15 | from model.proc.jroproc_base import ProcessingUnit, Operation | |
16 | from model.data.jroamisr import AMISR |
|
16 | from model.data.jroamisr import AMISR | |
17 |
|
17 | |||
18 | class RadacHeader(): |
|
18 | class RadacHeader(): | |
19 | def __init__(self, fp): |
|
19 | def __init__(self, fp): | |
20 | header = 'Raw11/Data/RadacHeader' |
|
20 | header = 'Raw11/Data/RadacHeader' | |
21 | self.beamCodeByPulse = fp.get(header+'/BeamCode') |
|
21 | self.beamCodeByPulse = fp.get(header+'/BeamCode') | |
22 | self.beamCode = fp.get('Raw11/Data/Beamcodes') |
|
22 | self.beamCode = fp.get('Raw11/Data/Beamcodes') | |
23 | self.code = fp.get(header+'/Code') |
|
23 | self.code = fp.get(header+'/Code') | |
24 | self.frameCount = fp.get(header+'/FrameCount') |
|
24 | self.frameCount = fp.get(header+'/FrameCount') | |
25 | self.modeGroup = fp.get(header+'/ModeGroup') |
|
25 | self.modeGroup = fp.get(header+'/ModeGroup') | |
26 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') |
|
26 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') | |
27 | self.pulseCount = fp.get(header+'/PulseCount') |
|
27 | self.pulseCount = fp.get(header+'/PulseCount') | |
28 | self.radacTime = fp.get(header+'/RadacTime') |
|
28 | self.radacTime = fp.get(header+'/RadacTime') | |
29 | self.timeCount = fp.get(header+'/TimeCount') |
|
29 | self.timeCount = fp.get(header+'/TimeCount') | |
30 | self.timeStatus = fp.get(header+'/TimeStatus') |
|
30 | self.timeStatus = fp.get(header+'/TimeStatus') | |
31 |
|
31 | |||
32 | self.nrecords = self.pulseCount.shape[0] #nblocks |
|
32 | self.nrecords = self.pulseCount.shape[0] #nblocks | |
33 | self.npulses = self.pulseCount.shape[1] #nprofile |
|
33 | self.npulses = self.pulseCount.shape[1] #nprofile | |
34 | self.nsamples = self.nsamplesPulse[0,0] #ngates |
|
34 | self.nsamples = self.nsamplesPulse[0,0] #ngates | |
35 | self.nbeams = self.beamCode.shape[1] |
|
35 | self.nbeams = self.beamCode.shape[1] | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | def getIndexRangeToPulse(self, idrecord=0): |
|
38 | def getIndexRangeToPulse(self, idrecord=0): | |
39 | #indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) |
|
39 | #indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) | |
40 | #startPulseCountId = indexToZero[0][0] |
|
40 | #startPulseCountId = indexToZero[0][0] | |
41 | #endPulseCountId = startPulseCountId - 1 |
|
41 | #endPulseCountId = startPulseCountId - 1 | |
42 | #range1 = numpy.arange(startPulseCountId,self.npulses,1) |
|
42 | #range1 = numpy.arange(startPulseCountId,self.npulses,1) | |
43 | #range2 = numpy.arange(0,startPulseCountId,1) |
|
43 | #range2 = numpy.arange(0,startPulseCountId,1) | |
44 | #return range1, range2 |
|
44 | #return range1, range2 | |
45 | zero = 0 |
|
45 | zero = 0 | |
46 | npulse = max(self.pulseCount[0,:]+1)-1 |
|
46 | npulse = max(self.pulseCount[0,:]+1)-1 | |
47 | looking_index = numpy.where(self.pulseCount.value[idrecord,:]==npulse)[0] |
|
47 | looking_index = numpy.where(self.pulseCount.value[idrecord,:]==npulse)[0] | |
48 | getLastIndex = looking_index[-1] |
|
48 | getLastIndex = looking_index[-1] | |
49 | index_data = numpy.arange(0,getLastIndex+1,1) |
|
49 | index_data = numpy.arange(0,getLastIndex+1,1) | |
50 | index_buffer = numpy.arange(getLastIndex+1,self.npulses,1) |
|
50 | index_buffer = numpy.arange(getLastIndex+1,self.npulses,1) | |
51 | return index_data, index_buffer |
|
51 | return index_data, index_buffer | |
52 |
|
52 | |||
53 | class AMISRReader(ProcessingUnit): |
|
53 | class AMISRReader(ProcessingUnit): | |
54 |
|
54 | |||
55 | path = None |
|
55 | path = None | |
56 | startDate = None |
|
56 | startDate = None | |
57 | endDate = None |
|
57 | endDate = None | |
58 | startTime = None |
|
58 | startTime = None | |
59 | endTime = None |
|
59 | endTime = None | |
60 | walk = None |
|
60 | walk = None | |
61 | isConfig = False |
|
61 | isConfig = False | |
62 |
|
62 | |||
63 | def __init__(self): |
|
63 | def __init__(self): | |
64 | self.set = None |
|
64 | self.set = None | |
65 | self.subset = None |
|
65 | self.subset = None | |
66 | self.extension_file = '.h5' |
|
66 | self.extension_file = '.h5' | |
67 | self.dtc_str = 'dtc' |
|
67 | self.dtc_str = 'dtc' | |
68 | self.dtc_id = 0 |
|
68 | self.dtc_id = 0 | |
69 | self.status = True |
|
69 | self.status = True | |
70 | self.isConfig = False |
|
70 | self.isConfig = False | |
71 | self.dirnameList = [] |
|
71 | self.dirnameList = [] | |
72 | self.filenameList = [] |
|
72 | self.filenameList = [] | |
73 | self.fileIndex = None |
|
73 | self.fileIndex = None | |
74 | self.flagNoMoreFiles = False |
|
74 | self.flagNoMoreFiles = False | |
75 | self.flagIsNewFile = 0 |
|
75 | self.flagIsNewFile = 0 | |
76 | self.filename = '' |
|
76 | self.filename = '' | |
77 | self.amisrFilePointer = None |
|
77 | self.amisrFilePointer = None | |
78 | self.radacHeaderObj = None |
|
78 | self.radacHeaderObj = None | |
79 | self.dataOut = self.__createObjByDefault() |
|
79 | self.dataOut = self.__createObjByDefault() | |
80 | self.datablock = None |
|
80 | self.datablock = None | |
81 | self.rest_datablock = None |
|
81 | self.rest_datablock = None | |
82 | self.range = None |
|
82 | self.range = None | |
83 | self.idrecord_count = 0 |
|
83 | self.idrecord_count = 0 | |
84 | self.profileIndex = 0 |
|
84 | self.profileIndex = 0 | |
85 | self.index_amisr_sample = None |
|
85 | self.index_amisr_sample = None | |
86 | self.index_amisr_buffer = None |
|
86 | self.index_amisr_buffer = None | |
87 | self.beamCodeByFrame = None |
|
87 | self.beamCodeByFrame = None | |
88 | self.radacTimeByFrame = None |
|
88 | self.radacTimeByFrame = None | |
89 | #atributos originales tal y como esta en el archivo de datos |
|
89 | #atributos originales tal y como esta en el archivo de datos | |
90 | self.beamCodesFromFile = None |
|
90 | self.beamCodesFromFile = None | |
91 | self.radacTimeFromFile = None |
|
91 | self.radacTimeFromFile = None | |
92 | self.rangeFromFile = None |
|
92 | self.rangeFromFile = None | |
93 | self.dataByFrame = None |
|
93 | self.dataByFrame = None | |
94 | self.dataset = None |
|
94 | self.dataset = None | |
95 |
|
95 | |||
96 | self.beamCodeDict = {} |
|
96 | self.beamCodeDict = {} | |
97 | self.beamRangeDict = {} |
|
97 | self.beamRangeDict = {} | |
98 |
|
98 | |||
99 | #experiment cgf file |
|
99 | #experiment cgf file | |
100 | self.npulsesint_fromfile = None |
|
100 | self.npulsesint_fromfile = None | |
101 | self.recordsperfile_fromfile = None |
|
101 | self.recordsperfile_fromfile = None | |
102 | self.nbeamcodes_fromfile = None |
|
102 | self.nbeamcodes_fromfile = None | |
103 | self.ngates_fromfile = None |
|
103 | self.ngates_fromfile = None | |
104 | self.ippSeconds_fromfile = None |
|
104 | self.ippSeconds_fromfile = None | |
105 | self.frequency_h5file = None |
|
105 | self.frequency_h5file = None | |
106 |
|
106 | |||
107 |
|
107 | |||
108 | self.__firstFile = True |
|
108 | self.__firstFile = True | |
109 | self.buffer_radactime = None |
|
109 | self.buffer_radactime = None | |
110 |
|
110 | |||
111 | self.index4_schain_datablock = None |
|
111 | self.index4_schain_datablock = None | |
112 | self.index4_buffer = None |
|
112 | self.index4_buffer = None | |
113 | self.schain_datablock = None |
|
113 | self.schain_datablock = None | |
114 | self.buffer = None |
|
114 | self.buffer = None | |
115 | self.linear_pulseCount = None |
|
115 | self.linear_pulseCount = None | |
116 | self.npulseByFrame = None |
|
116 | self.npulseByFrame = None | |
117 | self.profileIndex_offset = None |
|
117 | self.profileIndex_offset = None | |
118 | self.timezone = 'ut' |
|
118 | self.timezone = 'ut' | |
119 |
|
119 | |||
120 | self.__waitForNewFile = 20 |
|
120 | self.__waitForNewFile = 20 | |
121 | self.__filename_online = None |
|
121 | self.__filename_online = None | |
122 |
|
122 | |||
123 | def __createObjByDefault(self): |
|
123 | def __createObjByDefault(self): | |
124 |
|
124 | |||
125 | dataObj = AMISR() |
|
125 | dataObj = AMISR() | |
126 |
|
126 | |||
127 | return dataObj |
|
127 | return dataObj | |
128 |
|
128 | |||
129 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): |
|
129 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): | |
130 | self.path = path |
|
130 | self.path = path | |
131 | self.startDate = startDate |
|
131 | self.startDate = startDate | |
132 | self.endDate = endDate |
|
132 | self.endDate = endDate | |
133 | self.startTime = startTime |
|
133 | self.startTime = startTime | |
134 | self.endTime = endTime |
|
134 | self.endTime = endTime | |
135 | self.walk = walk |
|
135 | self.walk = walk | |
136 |
|
136 | |||
137 | def __checkPath(self): |
|
137 | def __checkPath(self): | |
138 | if os.path.exists(self.path): |
|
138 | if os.path.exists(self.path): | |
139 | self.status = 1 |
|
139 | self.status = 1 | |
140 | else: |
|
140 | else: | |
141 | self.status = 0 |
|
141 | self.status = 0 | |
142 | print 'Path:%s does not exists'%self.path |
|
142 | print 'Path:%s does not exists'%self.path | |
143 |
|
143 | |||
144 | return |
|
144 | return | |
145 |
|
145 | |||
146 | def __selDates(self, amisr_dirname_format): |
|
146 | def __selDates(self, amisr_dirname_format): | |
147 | try: |
|
147 | try: | |
148 | year = int(amisr_dirname_format[0:4]) |
|
148 | year = int(amisr_dirname_format[0:4]) | |
149 | month = int(amisr_dirname_format[4:6]) |
|
149 | month = int(amisr_dirname_format[4:6]) | |
150 | dom = int(amisr_dirname_format[6:8]) |
|
150 | dom = int(amisr_dirname_format[6:8]) | |
151 | thisDate = datetime.date(year,month,dom) |
|
151 | thisDate = datetime.date(year,month,dom) | |
152 |
|
152 | |||
153 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
153 | if (thisDate>=self.startDate and thisDate <= self.endDate): | |
154 | return amisr_dirname_format |
|
154 | return amisr_dirname_format | |
155 | except: |
|
155 | except: | |
156 | return None |
|
156 | return None | |
157 |
|
157 | |||
158 | def __findDataForDates(self,online=False): |
|
158 | def __findDataForDates(self,online=False): | |
159 |
|
159 | |||
160 |
|
160 | |||
161 |
|
161 | |||
162 | if not(self.status): |
|
162 | if not(self.status): | |
163 | return None |
|
163 | return None | |
164 |
|
164 | |||
165 | pat = '\d+.\d+' |
|
165 | pat = '\d+.\d+' | |
166 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] |
|
166 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] | |
167 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
167 | dirnameList = filter(lambda x:x!=None,dirnameList) | |
168 | dirnameList = [x.string for x in dirnameList] |
|
168 | dirnameList = [x.string for x in dirnameList] | |
169 | if not(online): |
|
169 | if not(online): | |
170 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
170 | dirnameList = [self.__selDates(x) for x in dirnameList] | |
171 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
171 | dirnameList = filter(lambda x:x!=None,dirnameList) | |
172 | if len(dirnameList)>0: |
|
172 | if len(dirnameList)>0: | |
173 | self.status = 1 |
|
173 | self.status = 1 | |
174 | self.dirnameList = dirnameList |
|
174 | self.dirnameList = dirnameList | |
175 | self.dirnameList.sort() |
|
175 | self.dirnameList.sort() | |
176 | else: |
|
176 | else: | |
177 | self.status = 0 |
|
177 | self.status = 0 | |
178 | return None |
|
178 | return None | |
179 |
|
179 | |||
180 | def __getTimeFromData(self): |
|
180 | def __getTimeFromData(self): | |
181 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) |
|
181 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) | |
182 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) |
|
182 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) | |
183 |
|
183 | |||
184 | print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader) |
|
184 | print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader) | |
185 | print '........................................' |
|
185 | print '........................................' | |
186 | filter_filenameList = [] |
|
186 | filter_filenameList = [] | |
187 | self.filenameList.sort() |
|
187 | self.filenameList.sort() | |
188 | for i in range(len(self.filenameList)-1): |
|
188 | for i in range(len(self.filenameList)-1): | |
189 | filename = self.filenameList[i] |
|
189 | filename = self.filenameList[i] | |
190 | fp = h5py.File(filename,'r') |
|
190 | fp = h5py.File(filename,'r') | |
191 | time_str = fp.get('Time/RadacTimeString') |
|
191 | time_str = fp.get('Time/RadacTimeString') | |
192 |
|
192 | |||
193 | startDateTimeStr_File = time_str[0][0].split('.')[0] |
|
193 | startDateTimeStr_File = time_str[0][0].split('.')[0] | |
194 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
194 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') | |
195 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
195 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) | |
196 |
|
196 | |||
197 | endDateTimeStr_File = time_str[-1][-1].split('.')[0] |
|
197 | endDateTimeStr_File = time_str[-1][-1].split('.')[0] | |
198 | junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
198 | junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S') | |
199 | endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
199 | endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) | |
200 |
|
200 | |||
201 | fp.close() |
|
201 | fp.close() | |
202 |
|
202 | |||
203 | if self.timezone == 'lt': |
|
203 | if self.timezone == 'lt': | |
204 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) |
|
204 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) | |
205 | endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300) |
|
205 | endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300) | |
206 |
|
206 | |||
207 | if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader): |
|
207 | if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader): | |
208 | #self.filenameList.remove(filename) |
|
208 | #self.filenameList.remove(filename) | |
209 | filter_filenameList.append(filename) |
|
209 | filter_filenameList.append(filename) | |
210 |
|
210 | |||
211 | filter_filenameList.sort() |
|
211 | filter_filenameList.sort() | |
212 | self.filenameList = filter_filenameList |
|
212 | self.filenameList = filter_filenameList | |
213 | return 1 |
|
213 | return 1 | |
214 |
|
214 | |||
215 | def __filterByGlob1(self, dirName): |
|
215 | def __filterByGlob1(self, dirName): | |
216 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) |
|
216 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) | |
217 | filterDict = {} |
|
217 | filterDict = {} | |
218 | filterDict.setdefault(dirName) |
|
218 | filterDict.setdefault(dirName) | |
219 | filterDict[dirName] = filter_files |
|
219 | filterDict[dirName] = filter_files | |
220 | return filterDict |
|
220 | return filterDict | |
221 |
|
221 | |||
222 | def __getFilenameList(self, fileListInKeys, dirList): |
|
222 | def __getFilenameList(self, fileListInKeys, dirList): | |
223 | for value in fileListInKeys: |
|
223 | for value in fileListInKeys: | |
224 | dirName = value.keys()[0] |
|
224 | dirName = value.keys()[0] | |
225 | for file in value[dirName]: |
|
225 | for file in value[dirName]: | |
226 | filename = os.path.join(dirName, file) |
|
226 | filename = os.path.join(dirName, file) | |
227 | self.filenameList.append(filename) |
|
227 | self.filenameList.append(filename) | |
228 |
|
228 | |||
229 |
|
229 | |||
230 | def __selectDataForTimes(self, online=False): |
|
230 | def __selectDataForTimes(self, online=False): | |
231 | #aun no esta implementado el filtro for tiempo |
|
231 | #aun no esta implementado el filtro for tiempo | |
232 | if not(self.status): |
|
232 | if not(self.status): | |
233 | return None |
|
233 | return None | |
234 |
|
234 | |||
235 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
235 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] | |
236 |
|
236 | |||
237 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] |
|
237 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] | |
238 |
|
238 | |||
239 | self.__getFilenameList(fileListInKeys, dirList) |
|
239 | self.__getFilenameList(fileListInKeys, dirList) | |
240 | if not(online): |
|
240 | if not(online): | |
241 | #filtro por tiempo |
|
241 | #filtro por tiempo | |
242 | if not(self.all): |
|
242 | if not(self.all): | |
243 | self.__getTimeFromData() |
|
243 | self.__getTimeFromData() | |
244 |
|
244 | |||
245 | if len(self.filenameList)>0: |
|
245 | if len(self.filenameList)>0: | |
246 | self.status = 1 |
|
246 | self.status = 1 | |
247 | self.filenameList.sort() |
|
247 | self.filenameList.sort() | |
248 | else: |
|
248 | else: | |
249 | self.status = 0 |
|
249 | self.status = 0 | |
250 | return None |
|
250 | return None | |
251 |
|
|
251 | ||
252 | else: |
|
252 | else: | |
253 | #get the last file - 1 |
|
253 | #get the last file - 1 | |
254 | self.filenameList = [self.filenameList[-2]] |
|
254 | self.filenameList = [self.filenameList[-2]] | |
255 | return 1 |
|
255 | ||
|
256 | new_dirnameList = [] | |||
|
257 | for dirname in self.dirnameList: | |||
|
258 | junk = numpy.array([dirname in x for x in self.filenameList]) | |||
|
259 | junk_sum = junk.sum() | |||
|
260 | if junk_sum > 0: | |||
|
261 | new_dirnameList.append(dirname) | |||
|
262 | self.dirnameList = new_dirnameList | |||
|
263 | return 1 | |||
256 |
|
264 | |||
257 | def __searchFilesOnline(self, |
|
265 | def __searchFilesOnline(self, | |
258 | path, |
|
266 | path, | |
259 | walk=True): |
|
267 | walk=True): | |
260 |
|
268 | |||
261 | startDate = datetime.datetime.utcnow().date() |
|
269 | startDate = datetime.datetime.utcnow().date() | |
262 | endDate = datetime.datetime.utcnow().date() |
|
270 | endDate = datetime.datetime.utcnow().date() | |
263 |
|
271 | |||
264 | self.__setParameters(path=path, startDate=startDate, endDate=endDate, walk=walk) |
|
272 | self.__setParameters(path=path, startDate=startDate, endDate=endDate, walk=walk) | |
265 |
|
273 | |||
266 | self.__checkPath() |
|
274 | self.__checkPath() | |
267 |
|
275 | |||
268 | self.__findDataForDates(online=True) |
|
276 | self.__findDataForDates(online=True) | |
269 |
|
277 | |||
270 | self.dirnameList = [self.dirnameList[-1]] |
|
278 | self.dirnameList = [self.dirnameList[-1]] | |
271 |
|
279 | |||
272 | self.__selectDataForTimes(online=True) |
|
280 | self.__selectDataForTimes(online=True) | |
273 |
|
281 | |||
274 | return |
|
282 | return | |
275 |
|
283 | |||
276 |
|
284 | |||
277 | def __searchFilesOffline(self, |
|
285 | def __searchFilesOffline(self, | |
278 | path, |
|
286 | path, | |
279 | startDate, |
|
287 | startDate, | |
280 | endDate, |
|
288 | endDate, | |
281 | startTime=datetime.time(0,0,0), |
|
289 | startTime=datetime.time(0,0,0), | |
282 | endTime=datetime.time(23,59,59), |
|
290 | endTime=datetime.time(23,59,59), | |
283 | walk=True): |
|
291 | walk=True): | |
284 |
|
292 | |||
285 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
293 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) | |
286 |
|
294 | |||
287 | self.__checkPath() |
|
295 | self.__checkPath() | |
288 |
|
296 | |||
289 | self.__findDataForDates() |
|
297 | self.__findDataForDates() | |
290 |
|
298 | |||
291 | self.__selectDataForTimes() |
|
299 | self.__selectDataForTimes() | |
292 |
|
300 | |||
293 | for i in range(len(self.filenameList)): |
|
301 | for i in range(len(self.filenameList)): | |
294 | print "%s" %(self.filenameList[i]) |
|
302 | print "%s" %(self.filenameList[i]) | |
295 |
|
303 | |||
296 | return |
|
304 | return | |
297 |
|
305 | |||
298 | def __setNextFileOffline(self): |
|
306 | def __setNextFileOffline(self): | |
299 | idFile = self.fileIndex |
|
307 | idFile = self.fileIndex | |
300 |
|
308 | |||
301 | while (True): |
|
309 | while (True): | |
302 | idFile += 1 |
|
310 | idFile += 1 | |
303 | if not(idFile < len(self.filenameList)): |
|
311 | if not(idFile < len(self.filenameList)): | |
304 | self.flagNoMoreFiles = 1 |
|
312 | self.flagNoMoreFiles = 1 | |
305 | print "No more Files" |
|
313 | print "No more Files" | |
306 | return 0 |
|
314 | return 0 | |
307 |
|
315 | |||
308 | filename = self.filenameList[idFile] |
|
316 | filename = self.filenameList[idFile] | |
309 |
|
317 | |||
310 | amisrFilePointer = h5py.File(filename,'r') |
|
318 | amisrFilePointer = h5py.File(filename,'r') | |
311 |
|
319 | |||
312 | break |
|
320 | break | |
313 |
|
321 | |||
314 | self.flagIsNewFile = 1 |
|
322 | self.flagIsNewFile = 1 | |
315 | self.fileIndex = idFile |
|
323 | self.fileIndex = idFile | |
316 | self.filename = filename |
|
324 | self.filename = filename | |
317 |
|
325 | |||
318 | self.amisrFilePointer = amisrFilePointer |
|
326 | self.amisrFilePointer = amisrFilePointer | |
319 |
|
327 | |||
320 | print "Setting the file: %s"%self.filename |
|
328 | print "Setting the file: %s"%self.filename | |
321 |
|
329 | |||
322 | return 1 |
|
330 | return 1 | |
323 |
|
331 | |||
324 |
|
332 | |||
325 | def __setNextFileOnline(self): |
|
333 | def __setNextFileOnline(self): | |
326 | filename = self.filenameList[0] |
|
334 | filename = self.filenameList[0] | |
327 | if self.__filename_online != None: |
|
335 | if self.__filename_online != None: | |
328 | self.__selectDataForTimes(online=True) |
|
336 | self.__selectDataForTimes(online=True) | |
329 | filename = self.filenameList[0] |
|
337 | filename = self.filenameList[0] | |
330 | while self.__filename_online == filename: |
|
338 | while self.__filename_online == filename: | |
331 | print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) |
|
339 | print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) | |
332 | time.sleep(self.__waitForNewFile) |
|
340 | time.sleep(self.__waitForNewFile) | |
333 | self.__selectDataForTimes(online=True) |
|
341 | self.__selectDataForTimes(online=True) | |
334 | filename = self.filenameList[0] |
|
342 | filename = self.filenameList[0] | |
335 |
|
343 | |||
336 | self.__filename_online = filename |
|
344 | self.__filename_online = filename | |
337 |
|
345 | |||
338 | self.amisrFilePointer = h5py.File(filename,'r') |
|
346 | self.amisrFilePointer = h5py.File(filename,'r') | |
339 | self.flagIsNewFile = 1 |
|
347 | self.flagIsNewFile = 1 | |
340 | self.filename = filename |
|
348 | self.filename = filename | |
341 | print "Setting the file: %s"%self.filename |
|
349 | print "Setting the file: %s"%self.filename | |
342 | return 1 |
|
350 | return 1 | |
343 |
|
351 | |||
344 |
|
352 | |||
345 | def __readHeader(self): |
|
353 | def __readHeader(self): | |
346 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) |
|
354 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) | |
347 |
|
355 | |||
348 | #update values from experiment cfg file |
|
356 | #update values from experiment cfg file | |
349 | if self.radacHeaderObj.nrecords == self.recordsperfile_fromfile: |
|
357 | if self.radacHeaderObj.nrecords == self.recordsperfile_fromfile: | |
350 | self.radacHeaderObj.nrecords = self.recordsperfile_fromfile |
|
358 | self.radacHeaderObj.nrecords = self.recordsperfile_fromfile | |
351 | self.radacHeaderObj.nbeams = self.nbeamcodes_fromfile |
|
359 | self.radacHeaderObj.nbeams = self.nbeamcodes_fromfile | |
352 | self.radacHeaderObj.npulses = self.npulsesint_fromfile |
|
360 | self.radacHeaderObj.npulses = self.npulsesint_fromfile | |
353 | self.radacHeaderObj.nsamples = self.ngates_fromfile |
|
361 | self.radacHeaderObj.nsamples = self.ngates_fromfile | |
354 |
|
362 | |||
355 | #looking index list for data |
|
363 | #looking index list for data | |
356 | start_index = self.radacHeaderObj.pulseCount[0,:][0] |
|
364 | start_index = self.radacHeaderObj.pulseCount[0,:][0] | |
357 | end_index = self.radacHeaderObj.npulses |
|
365 | end_index = self.radacHeaderObj.npulses | |
358 | range4data = range(start_index, end_index) |
|
366 | range4data = range(start_index, end_index) | |
359 | self.index4_schain_datablock = numpy.array(range4data) |
|
367 | self.index4_schain_datablock = numpy.array(range4data) | |
360 |
|
368 | |||
361 | buffer_start_index = 0 |
|
369 | buffer_start_index = 0 | |
362 | buffer_end_index = self.radacHeaderObj.pulseCount[0,:][0] |
|
370 | buffer_end_index = self.radacHeaderObj.pulseCount[0,:][0] | |
363 | range4buffer = range(buffer_start_index, buffer_end_index) |
|
371 | range4buffer = range(buffer_start_index, buffer_end_index) | |
364 | self.index4_buffer = numpy.array(range4buffer) |
|
372 | self.index4_buffer = numpy.array(range4buffer) | |
365 |
|
373 | |||
366 | self.linear_pulseCount = numpy.array(range4data + range4buffer) |
|
374 | self.linear_pulseCount = numpy.array(range4data + range4buffer) | |
367 | self.npulseByFrame = max(self.radacHeaderObj.pulseCount[0,:]+1) |
|
375 | self.npulseByFrame = max(self.radacHeaderObj.pulseCount[0,:]+1) | |
368 |
|
376 | |||
369 | #get tuning frequency |
|
377 | #get tuning frequency | |
370 | frequency_h5file_dataset = self.amisrFilePointer.get('Rx'+'/TuningFrequency') |
|
378 | frequency_h5file_dataset = self.amisrFilePointer.get('Rx'+'/TuningFrequency') | |
371 | self.frequency_h5file = frequency_h5file_dataset[0,0] |
|
379 | self.frequency_h5file = frequency_h5file_dataset[0,0] | |
372 |
|
380 | |||
373 | self.flagIsNewFile = 1 |
|
381 | self.flagIsNewFile = 1 | |
374 |
|
382 | |||
375 | def __getBeamCode(self): |
|
383 | def __getBeamCode(self): | |
376 | self.beamCodeDict = {} |
|
384 | self.beamCodeDict = {} | |
377 | self.beamRangeDict = {} |
|
385 | self.beamRangeDict = {} | |
378 |
|
386 | |||
379 | beamCodeMap = self.amisrFilePointer.get('Setup/BeamcodeMap') |
|
387 | beamCodeMap = self.amisrFilePointer.get('Setup/BeamcodeMap') | |
380 |
|
388 | |||
381 | for i in range(len(self.radacHeaderObj.beamCode[0,:])): |
|
389 | for i in range(len(self.radacHeaderObj.beamCode[0,:])): | |
382 | self.beamCodeDict.setdefault(i) |
|
390 | self.beamCodeDict.setdefault(i) | |
383 | self.beamRangeDict.setdefault(i) |
|
391 | self.beamRangeDict.setdefault(i) | |
384 | beamcodeValue = self.radacHeaderObj.beamCode[0,i] |
|
392 | beamcodeValue = self.radacHeaderObj.beamCode[0,i] | |
385 | beamcodeIndex = numpy.where(beamCodeMap[:,0] == beamcodeValue)[0][0] |
|
393 | beamcodeIndex = numpy.where(beamCodeMap[:,0] == beamcodeValue)[0][0] | |
386 | x = beamCodeMap[beamcodeIndex][1] |
|
394 | x = beamCodeMap[beamcodeIndex][1] | |
387 | y = beamCodeMap[beamcodeIndex][2] |
|
395 | y = beamCodeMap[beamcodeIndex][2] | |
388 | z = beamCodeMap[beamcodeIndex][3] |
|
396 | z = beamCodeMap[beamcodeIndex][3] | |
389 | self.beamCodeDict[i] = [beamcodeValue, x, y, z] |
|
397 | self.beamCodeDict[i] = [beamcodeValue, x, y, z] | |
390 |
|
398 | |||
391 | just4record0 = self.radacHeaderObj.beamCodeByPulse[0,:] |
|
399 | just4record0 = self.radacHeaderObj.beamCodeByPulse[0,:] | |
392 |
|
400 | |||
393 | for i in range(len(self.beamCodeDict.values())): |
|
401 | for i in range(len(self.beamCodeDict.values())): | |
394 | xx = numpy.where(just4record0==self.beamCodeDict.values()[i][0]) |
|
402 | xx = numpy.where(just4record0==self.beamCodeDict.values()[i][0]) | |
395 | indexPulseByBeam = self.linear_pulseCount[xx[0]] |
|
403 | indexPulseByBeam = self.linear_pulseCount[xx[0]] | |
396 | self.beamRangeDict[i] = indexPulseByBeam |
|
404 | self.beamRangeDict[i] = indexPulseByBeam | |
397 |
|
405 | |||
398 | def __getExpParameters(self): |
|
406 | def __getExpParameters(self): | |
399 | if not(self.status): |
|
407 | if not(self.status): | |
400 | return None |
|
408 | return None | |
401 |
|
409 | |||
402 | experimentCfgPath = os.path.join(self.path, self.dirnameList[0], 'Setup') |
|
410 | experimentCfgPath = os.path.join(self.path, self.dirnameList[0], 'Setup') | |
403 |
|
411 | |||
404 | expFinder = glob.glob1(experimentCfgPath,'*.exp') |
|
412 | expFinder = glob.glob1(experimentCfgPath,'*.exp') | |
405 | if len(expFinder)== 0: |
|
413 | if len(expFinder)== 0: | |
406 | self.status = 0 |
|
414 | self.status = 0 | |
407 | return None |
|
415 | return None | |
408 |
|
416 | |||
409 | experimentFilename = os.path.join(experimentCfgPath,expFinder[0]) |
|
417 | experimentFilename = os.path.join(experimentCfgPath,expFinder[0]) | |
410 |
|
418 | |||
411 | f = open(experimentFilename) |
|
419 | f = open(experimentFilename) | |
412 | lines = f.readlines() |
|
420 | lines = f.readlines() | |
413 | f.close() |
|
421 | f.close() | |
414 |
|
422 | |||
415 | parmsList = ['npulsesint*','recordsperfile*','nbeamcodes*','ngates*'] |
|
423 | parmsList = ['npulsesint*','recordsperfile*','nbeamcodes*','ngates*'] | |
416 | filterList = [fnmatch.filter(lines, x) for x in parmsList] |
|
424 | filterList = [fnmatch.filter(lines, x) for x in parmsList] | |
417 |
|
425 | |||
418 |
|
426 | |||
419 | values = [re.sub(r'\D',"",x[0]) for x in filterList] |
|
427 | values = [re.sub(r'\D',"",x[0]) for x in filterList] | |
420 |
|
428 | |||
421 | self.npulsesint_fromfile = int(values[0]) |
|
429 | self.npulsesint_fromfile = int(values[0]) | |
422 | self.recordsperfile_fromfile = int(values[1]) |
|
430 | self.recordsperfile_fromfile = int(values[1]) | |
423 | self.nbeamcodes_fromfile = int(values[2]) |
|
431 | self.nbeamcodes_fromfile = int(values[2]) | |
424 | self.ngates_fromfile = int(values[3]) |
|
432 | self.ngates_fromfile = int(values[3]) | |
425 |
|
433 | |||
426 | tufileFinder = fnmatch.filter(lines, 'tufile=*') |
|
434 | tufileFinder = fnmatch.filter(lines, 'tufile=*') | |
427 | tufile = tufileFinder[0].split('=')[1].split('\n')[0] |
|
435 | tufile = tufileFinder[0].split('=')[1].split('\n')[0] | |
428 | tufile = tufile.split('\r')[0] |
|
436 | tufile = tufile.split('\r')[0] | |
429 | tufilename = os.path.join(experimentCfgPath,tufile) |
|
437 | tufilename = os.path.join(experimentCfgPath,tufile) | |
430 |
|
438 | |||
431 | f = open(tufilename) |
|
439 | f = open(tufilename) | |
432 | lines = f.readlines() |
|
440 | lines = f.readlines() | |
433 | f.close() |
|
441 | f.close() | |
434 | self.ippSeconds_fromfile = float(lines[1].split()[2])/1E6 |
|
442 | self.ippSeconds_fromfile = float(lines[1].split()[2])/1E6 | |
435 |
|
443 | |||
436 |
|
444 | |||
437 | self.status = 1 |
|
445 | self.status = 1 | |
438 |
|
446 | |||
439 | def __setIdsAndArrays(self): |
|
447 | def __setIdsAndArrays(self): | |
440 | self.dataByFrame = self.__setDataByFrame() |
|
448 | self.dataByFrame = self.__setDataByFrame() | |
441 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[0, :] |
|
449 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[0, :] | |
442 | self.readRanges() |
|
450 | self.readRanges() | |
443 | self.index_amisr_sample, self.index_amisr_buffer = self.radacHeaderObj.getIndexRangeToPulse(0) |
|
451 | self.index_amisr_sample, self.index_amisr_buffer = self.radacHeaderObj.getIndexRangeToPulse(0) | |
444 | self.radacTimeByFrame = numpy.zeros(self.radacHeaderObj.npulses) |
|
452 | self.radacTimeByFrame = numpy.zeros(self.radacHeaderObj.npulses) | |
445 | if len(self.index_amisr_buffer) > 0: |
|
453 | if len(self.index_amisr_buffer) > 0: | |
446 | self.buffer_radactime = numpy.zeros_like(self.radacTimeByFrame) |
|
454 | self.buffer_radactime = numpy.zeros_like(self.radacTimeByFrame) | |
447 |
|
455 | |||
448 |
|
456 | |||
449 | def __setNextFile(self,online=False): |
|
457 | def __setNextFile(self,online=False): | |
450 |
|
458 | |||
451 | if not(online): |
|
459 | if not(online): | |
452 | newFile = self.__setNextFileOffline() |
|
460 | newFile = self.__setNextFileOffline() | |
453 | else: |
|
461 | else: | |
454 | newFile = self.__setNextFileOnline() |
|
462 | newFile = self.__setNextFileOnline() | |
455 |
|
463 | |||
456 | if not(newFile): |
|
464 | if not(newFile): | |
457 | return 0 |
|
465 | return 0 | |
458 |
|
466 | |||
459 | self.__readHeader() |
|
467 | self.__readHeader() | |
460 |
|
468 | |||
461 | if self.__firstFile: |
|
469 | if self.__firstFile: | |
462 | self.__setIdsAndArrays() |
|
470 | self.__setIdsAndArrays() | |
463 | self.__firstFile = False |
|
471 | self.__firstFile = False | |
464 |
|
472 | |||
465 | self.__getBeamCode() |
|
473 | self.__getBeamCode() | |
466 | self.readDataBlock() |
|
474 | self.readDataBlock() | |
467 |
|
475 | |||
468 |
|
476 | |||
469 | def setup(self,path=None, |
|
477 | def setup(self,path=None, | |
470 | startDate=None, |
|
478 | startDate=None, | |
471 | endDate=None, |
|
479 | endDate=None, | |
472 | startTime=datetime.time(0,0,0), |
|
480 | startTime=datetime.time(0,0,0), | |
473 | endTime=datetime.time(23,59,59), |
|
481 | endTime=datetime.time(23,59,59), | |
474 | walk=True, |
|
482 | walk=True, | |
475 | timezone='ut', |
|
483 | timezone='ut', | |
476 | all=0, |
|
484 | all=0, | |
477 | online=False): |
|
485 | online=False): | |
478 |
|
486 | |||
479 | self.timezone = timezone |
|
487 | self.timezone = timezone | |
480 | self.all = all |
|
488 | self.all = all | |
481 | self.online = online |
|
489 | self.online = online | |
482 | if not(online): |
|
490 | if not(online): | |
483 | #Busqueda de archivos offline |
|
491 | #Busqueda de archivos offline | |
484 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) |
|
492 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) | |
485 | else: |
|
493 | else: | |
486 | self.__searchFilesOnline(path, walk) |
|
494 | self.__searchFilesOnline(path, walk) | |
487 |
|
495 | |||
488 | if not(self.filenameList): |
|
496 | if not(self.filenameList): | |
489 | print "There is no files into the folder: %s"%(path) |
|
497 | print "There is no files into the folder: %s"%(path) | |
490 |
|
498 | |||
491 | sys.exit(-1) |
|
499 | sys.exit(-1) | |
492 |
|
500 | |||
493 | self.__getExpParameters() |
|
501 | self.__getExpParameters() | |
494 |
|
502 | |||
495 | self.fileIndex = -1 |
|
503 | self.fileIndex = -1 | |
496 |
|
504 | |||
497 | self.__setNextFile(online) |
|
505 | self.__setNextFile(online) | |
498 |
|
506 | |||
499 | # first_beamcode = self.radacHeaderObj.beamCodeByPulse[0,0] |
|
507 | # first_beamcode = self.radacHeaderObj.beamCodeByPulse[0,0] | |
500 | # index = numpy.where(self.radacHeaderObj.beamCodeByPulse[0,:]!=first_beamcode)[0][0] |
|
508 | # index = numpy.where(self.radacHeaderObj.beamCodeByPulse[0,:]!=first_beamcode)[0][0] | |
501 | self.profileIndex_offset = self.radacHeaderObj.pulseCount[0,:][0] |
|
509 | self.profileIndex_offset = self.radacHeaderObj.pulseCount[0,:][0] | |
502 | self.profileIndex = self.profileIndex_offset |
|
510 | self.profileIndex = self.profileIndex_offset | |
503 |
|
511 | |||
504 | def readRanges(self): |
|
512 | def readRanges(self): | |
505 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') |
|
513 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') | |
506 |
|
514 | |||
507 | self.rangeFromFile = numpy.reshape(dataset.value,(-1)) |
|
515 | self.rangeFromFile = numpy.reshape(dataset.value,(-1)) | |
508 | return self.rangeFromFile |
|
516 | return self.rangeFromFile | |
509 |
|
517 | |||
510 |
|
518 | |||
511 | def readRadacTime(self,idrecord, range1, range2): |
|
519 | def readRadacTime(self,idrecord, range1, range2): | |
512 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value |
|
520 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value | |
513 |
|
521 | |||
514 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
522 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) | |
515 | #radacTimeByFrame = dataset[idrecord - 1,range1] |
|
523 | #radacTimeByFrame = dataset[idrecord - 1,range1] | |
516 | #radacTimeByFrame = dataset[idrecord,range2] |
|
524 | #radacTimeByFrame = dataset[idrecord,range2] | |
517 |
|
525 | |||
518 | return radacTimeByFrame |
|
526 | return radacTimeByFrame | |
519 |
|
527 | |||
520 | def readBeamCode(self, idrecord, range1, range2): |
|
528 | def readBeamCode(self, idrecord, range1, range2): | |
521 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') |
|
529 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') | |
522 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
530 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) | |
523 | self.beamCodesFromFile = dataset.value |
|
531 | self.beamCodesFromFile = dataset.value | |
524 |
|
532 | |||
525 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] |
|
533 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] | |
526 | #beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
534 | #beamcodeByFrame[range2] = dataset[idrecord, range2] | |
527 | beamcodeByFrame[range1] = dataset[idrecord, range1] |
|
535 | beamcodeByFrame[range1] = dataset[idrecord, range1] | |
528 | beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
536 | beamcodeByFrame[range2] = dataset[idrecord, range2] | |
529 |
|
537 | |||
530 | return beamcodeByFrame |
|
538 | return beamcodeByFrame | |
531 |
|
539 | |||
532 |
|
540 | |||
533 | def __setDataByFrame(self): |
|
541 | def __setDataByFrame(self): | |
534 | ndata = 2 # porque es complejo |
|
542 | ndata = 2 # porque es complejo | |
535 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) |
|
543 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) | |
536 | return dataByFrame |
|
544 | return dataByFrame | |
537 |
|
545 | |||
538 | def __readDataSet(self): |
|
546 | def __readDataSet(self): | |
539 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') |
|
547 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') | |
540 | return dataset |
|
548 | return dataset | |
541 |
|
549 | |||
542 | def __setDataBlock(self,): |
|
550 | def __setDataBlock(self,): | |
543 | real = self.dataByFrame[:,:,0] #asumo que 0 es real |
|
551 | real = self.dataByFrame[:,:,0] #asumo que 0 es real | |
544 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario |
|
552 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario | |
545 | datablock = real + imag*1j #armo el complejo |
|
553 | datablock = real + imag*1j #armo el complejo | |
546 | return datablock |
|
554 | return datablock | |
547 |
|
555 | |||
548 | def readSamples_version1(self,idrecord): |
|
556 | def readSamples_version1(self,idrecord): | |
549 | #estas tres primeras lineas solo se deben ejecutar una vez |
|
557 | #estas tres primeras lineas solo se deben ejecutar una vez | |
550 | if self.flagIsNewFile: |
|
558 | if self.flagIsNewFile: | |
551 | #reading dataset |
|
559 | #reading dataset | |
552 | self.dataset = self.__readDataSet() |
|
560 | self.dataset = self.__readDataSet() | |
553 | self.flagIsNewFile = 0 |
|
561 | self.flagIsNewFile = 0 | |
554 |
|
562 | |||
555 | if idrecord == 0: |
|
563 | if idrecord == 0: | |
556 | self.dataByFrame[self.index4_schain_datablock, : ,:] = self.dataset[0, self.index_amisr_sample,:,:] |
|
564 | self.dataByFrame[self.index4_schain_datablock, : ,:] = self.dataset[0, self.index_amisr_sample,:,:] | |
557 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[0, self.index_amisr_sample] |
|
565 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[0, self.index_amisr_sample] | |
558 | datablock = self.__setDataBlock() |
|
566 | datablock = self.__setDataBlock() | |
559 | if len(self.index_amisr_buffer) > 0: |
|
567 | if len(self.index_amisr_buffer) > 0: | |
560 | self.buffer = self.dataset[0, self.index_amisr_buffer,:,:] |
|
568 | self.buffer = self.dataset[0, self.index_amisr_buffer,:,:] | |
561 | self.buffer_radactime = self.radacHeaderObj.radacTime[0, self.index_amisr_buffer] |
|
569 | self.buffer_radactime = self.radacHeaderObj.radacTime[0, self.index_amisr_buffer] | |
562 |
|
570 | |||
563 | return datablock |
|
571 | return datablock | |
564 | if len(self.index_amisr_buffer) > 0: |
|
572 | if len(self.index_amisr_buffer) > 0: | |
565 | self.dataByFrame[self.index4_buffer,:,:] = self.buffer.copy() |
|
573 | self.dataByFrame[self.index4_buffer,:,:] = self.buffer.copy() | |
566 | self.radacTimeByFrame[self.index4_buffer] = self.buffer_radactime.copy() |
|
574 | self.radacTimeByFrame[self.index4_buffer] = self.buffer_radactime.copy() | |
567 | self.dataByFrame[self.index4_schain_datablock,:,:] = self.dataset[idrecord, self.index_amisr_sample,:,:] |
|
575 | self.dataByFrame[self.index4_schain_datablock,:,:] = self.dataset[idrecord, self.index_amisr_sample,:,:] | |
568 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_sample] |
|
576 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_sample] | |
569 | datablock = self.__setDataBlock() |
|
577 | datablock = self.__setDataBlock() | |
570 | if len(self.index_amisr_buffer) > 0: |
|
578 | if len(self.index_amisr_buffer) > 0: | |
571 | self.buffer = self.dataset[idrecord, self.index_amisr_buffer, :, :] |
|
579 | self.buffer = self.dataset[idrecord, self.index_amisr_buffer, :, :] | |
572 | self.buffer_radactime = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_buffer] |
|
580 | self.buffer_radactime = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_buffer] | |
573 |
|
581 | |||
574 | return datablock |
|
582 | return datablock | |
575 |
|
583 | |||
576 |
|
584 | |||
577 | def readSamples(self,idrecord): |
|
585 | def readSamples(self,idrecord): | |
578 | if self.flagIsNewFile: |
|
586 | if self.flagIsNewFile: | |
579 | self.dataByFrame = self.__setDataByFrame() |
|
587 | self.dataByFrame = self.__setDataByFrame() | |
580 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] |
|
588 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] | |
581 |
|
589 | |||
582 | #reading ranges |
|
590 | #reading ranges | |
583 | self.readRanges() |
|
591 | self.readRanges() | |
584 | #reading dataset |
|
592 | #reading dataset | |
585 | self.dataset = self.__readDataSet() |
|
593 | self.dataset = self.__readDataSet() | |
586 |
|
594 | |||
587 | self.flagIsNewFile = 0 |
|
595 | self.flagIsNewFile = 0 | |
588 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] |
|
596 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] | |
589 | self.dataByFrame = self.dataset[idrecord, :, :, :] |
|
597 | self.dataByFrame = self.dataset[idrecord, :, :, :] | |
590 | datablock = self.__setDataBlock() |
|
598 | datablock = self.__setDataBlock() | |
591 | return datablock |
|
599 | return datablock | |
592 |
|
600 | |||
593 |
|
601 | |||
594 | def readDataBlock(self): |
|
602 | def readDataBlock(self): | |
595 |
|
603 | |||
596 | self.datablock = self.readSamples_version1(self.idrecord_count) |
|
604 | self.datablock = self.readSamples_version1(self.idrecord_count) | |
597 | #self.datablock = self.readSamples(self.idrecord_count) |
|
605 | #self.datablock = self.readSamples(self.idrecord_count) | |
598 | #print 'record:', self.idrecord_count |
|
606 | #print 'record:', self.idrecord_count | |
599 |
|
607 | |||
600 | self.idrecord_count += 1 |
|
608 | self.idrecord_count += 1 | |
601 | self.profileIndex = 0 |
|
609 | self.profileIndex = 0 | |
602 |
|
610 | |||
603 | if self.idrecord_count >= self.radacHeaderObj.nrecords: |
|
611 | if self.idrecord_count >= self.radacHeaderObj.nrecords: | |
604 | self.idrecord_count = 0 |
|
612 | self.idrecord_count = 0 | |
605 | self.flagIsNewFile = 1 |
|
613 | self.flagIsNewFile = 1 | |
606 |
|
614 | |||
607 | def readNextBlock(self): |
|
615 | def readNextBlock(self): | |
608 |
|
616 | |||
609 | self.readDataBlock() |
|
617 | self.readDataBlock() | |
610 |
|
618 | |||
611 | if self.flagIsNewFile: |
|
619 | if self.flagIsNewFile: | |
612 | self.__setNextFile(self.online) |
|
620 | self.__setNextFile(self.online) | |
613 | pass |
|
621 | pass | |
614 |
|
622 | |||
615 | def __hasNotDataInBuffer(self): |
|
623 | def __hasNotDataInBuffer(self): | |
616 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record |
|
624 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record | |
617 | if self.profileIndex >= self.radacHeaderObj.npulses: |
|
625 | if self.profileIndex >= self.radacHeaderObj.npulses: | |
618 | return 1 |
|
626 | return 1 | |
619 | return 0 |
|
627 | return 0 | |
620 |
|
628 | |||
621 | def printUTC(self): |
|
629 | def printUTC(self): | |
622 | print self.dataOut.utctime |
|
630 | print self.dataOut.utctime | |
623 | print '' |
|
631 | print '' | |
624 |
|
632 | |||
625 | def setObjProperties(self): |
|
633 | def setObjProperties(self): | |
626 | self.dataOut.heightList = self.rangeFromFile/1000.0 #km |
|
634 | self.dataOut.heightList = self.rangeFromFile/1000.0 #km | |
627 | self.dataOut.nProfiles = self.radacHeaderObj.npulses |
|
635 | self.dataOut.nProfiles = self.radacHeaderObj.npulses | |
628 | self.dataOut.nRecords = self.radacHeaderObj.nrecords |
|
636 | self.dataOut.nRecords = self.radacHeaderObj.nrecords | |
629 | self.dataOut.nBeams = self.radacHeaderObj.nbeams |
|
637 | self.dataOut.nBeams = self.radacHeaderObj.nbeams | |
630 | self.dataOut.ippSeconds = self.ippSeconds_fromfile |
|
638 | self.dataOut.ippSeconds = self.ippSeconds_fromfile | |
631 | self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
639 | self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
632 | self.dataOut.frequency = self.frequency_h5file |
|
640 | self.dataOut.frequency = self.frequency_h5file | |
633 | self.dataOut.npulseByFrame = self.npulseByFrame |
|
641 | self.dataOut.npulseByFrame = self.npulseByFrame | |
634 | self.dataOut.nBaud = None |
|
642 | self.dataOut.nBaud = None | |
635 | self.dataOut.nCode = None |
|
643 | self.dataOut.nCode = None | |
636 | self.dataOut.code = None |
|
644 | self.dataOut.code = None | |
637 |
|
645 | |||
638 | self.dataOut.beamCodeDict = self.beamCodeDict |
|
646 | self.dataOut.beamCodeDict = self.beamCodeDict | |
639 | self.dataOut.beamRangeDict = self.beamRangeDict |
|
647 | self.dataOut.beamRangeDict = self.beamRangeDict | |
640 |
|
648 | |||
641 | if self.timezone == 'lt': |
|
649 | if self.timezone == 'lt': | |
642 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes |
|
650 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes | |
643 | else: |
|
651 | else: | |
644 | self.dataOut.timeZone = 0 #by default time is UTC |
|
652 | self.dataOut.timeZone = 0 #by default time is UTC | |
645 |
|
653 | |||
646 | def getData(self): |
|
654 | def getData(self): | |
647 |
|
655 | |||
648 | if self.flagNoMoreFiles: |
|
656 | if self.flagNoMoreFiles: | |
649 | self.dataOut.flagNoData = True |
|
657 | self.dataOut.flagNoData = True | |
650 | print 'Process finished' |
|
658 | print 'Process finished' | |
651 | return 0 |
|
659 | return 0 | |
652 |
|
660 | |||
653 | if self.__hasNotDataInBuffer(): |
|
661 | if self.__hasNotDataInBuffer(): | |
654 | self.readNextBlock() |
|
662 | self.readNextBlock() | |
655 |
|
663 | |||
656 |
|
664 | |||
657 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
665 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers | |
658 | self.dataOut.flagNoData = True |
|
666 | self.dataOut.flagNoData = True | |
659 | return 0 |
|
667 | return 0 | |
660 |
|
668 | |||
661 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) |
|
669 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) | |
662 |
|
670 | |||
663 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] |
|
671 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] | |
664 | self.dataOut.profileIndex = self.profileIndex |
|
672 | self.dataOut.profileIndex = self.profileIndex | |
665 | self.dataOut.flagNoData = False |
|
673 | self.dataOut.flagNoData = False | |
666 |
|
674 | |||
667 | self.profileIndex += 1 |
|
675 | self.profileIndex += 1 | |
668 |
|
676 | |||
669 | return self.dataOut.data |
|
677 | return self.dataOut.data | |
670 |
|
678 | |||
671 |
|
679 | |||
672 | def run(self, **kwargs): |
|
680 | def run(self, **kwargs): | |
673 | if not(self.isConfig): |
|
681 | if not(self.isConfig): | |
674 | self.setup(**kwargs) |
|
682 | self.setup(**kwargs) | |
675 | self.setObjProperties() |
|
683 | self.setObjProperties() | |
676 | self.isConfig = True |
|
684 | self.isConfig = True | |
677 |
|
685 | |||
678 | self.getData() |
|
686 | self.getData() |
@@ -1,758 +1,758 | |||||
1 | import numpy |
|
1 | import numpy | |
2 |
|
2 | |||
3 | from jroproc_base import ProcessingUnit, Operation |
|
3 | from jroproc_base import ProcessingUnit, Operation | |
4 | from model.data.jrodata import Voltage |
|
4 | from model.data.jrodata import Voltage | |
5 |
|
5 | |||
6 | class VoltageProc(ProcessingUnit): |
|
6 | class VoltageProc(ProcessingUnit): | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | def __init__(self): |
|
9 | def __init__(self): | |
10 |
|
10 | |||
11 | ProcessingUnit.__init__(self) |
|
11 | ProcessingUnit.__init__(self) | |
12 |
|
12 | |||
13 | # self.objectDict = {} |
|
13 | # self.objectDict = {} | |
14 | self.dataOut = Voltage() |
|
14 | self.dataOut = Voltage() | |
15 | self.flip = 1 |
|
15 | self.flip = 1 | |
16 |
|
16 | |||
17 | def run(self): |
|
17 | def run(self): | |
18 | if self.dataIn.type == 'AMISR': |
|
18 | if self.dataIn.type == 'AMISR': | |
19 | self.__updateObjFromAmisrInput() |
|
19 | self.__updateObjFromAmisrInput() | |
20 |
|
20 | |||
21 | if self.dataIn.type == 'Voltage': |
|
21 | if self.dataIn.type == 'Voltage': | |
22 | self.dataOut.copy(self.dataIn) |
|
22 | self.dataOut.copy(self.dataIn) | |
23 |
|
23 | |||
24 | # self.dataOut.copy(self.dataIn) |
|
24 | # self.dataOut.copy(self.dataIn) | |
25 |
|
25 | |||
26 | def __updateObjFromAmisrInput(self): |
|
26 | def __updateObjFromAmisrInput(self): | |
27 |
|
27 | |||
28 | self.dataOut.timeZone = self.dataIn.timeZone |
|
28 | self.dataOut.timeZone = self.dataIn.timeZone | |
29 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
29 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
30 | self.dataOut.errorCount = self.dataIn.errorCount |
|
30 | self.dataOut.errorCount = self.dataIn.errorCount | |
31 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
31 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
32 |
|
32 | |||
33 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
33 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
34 | self.dataOut.data = self.dataIn.data |
|
34 | self.dataOut.data = self.dataIn.data | |
35 | self.dataOut.utctime = self.dataIn.utctime |
|
35 | self.dataOut.utctime = self.dataIn.utctime | |
36 | self.dataOut.channelList = self.dataIn.channelList |
|
36 | self.dataOut.channelList = self.dataIn.channelList | |
37 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
37 | self.dataOut.timeInterval = self.dataIn.timeInterval | |
38 | self.dataOut.heightList = self.dataIn.heightList |
|
38 | self.dataOut.heightList = self.dataIn.heightList | |
39 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
39 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
40 |
|
40 | |||
41 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
41 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
42 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
42 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
43 | self.dataOut.frequency = self.dataIn.frequency |
|
43 | self.dataOut.frequency = self.dataIn.frequency | |
44 |
|
44 | |||
45 | self.dataOut.azimuth = self.dataIn.azimuth |
|
45 | self.dataOut.azimuth = self.dataIn.azimuth | |
46 | self.dataOut.zenith = self.dataIn.zenith |
|
46 | self.dataOut.zenith = self.dataIn.zenith | |
47 |
|
47 | |||
48 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
48 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
49 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
49 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
50 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
50 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
51 | # |
|
51 | # | |
52 | # pass# |
|
52 | # pass# | |
53 | # |
|
53 | # | |
54 | # def init(self): |
|
54 | # def init(self): | |
55 | # |
|
55 | # | |
56 | # |
|
56 | # | |
57 | # if self.dataIn.type == 'AMISR': |
|
57 | # if self.dataIn.type == 'AMISR': | |
58 | # self.__updateObjFromAmisrInput() |
|
58 | # self.__updateObjFromAmisrInput() | |
59 | # |
|
59 | # | |
60 | # if self.dataIn.type == 'Voltage': |
|
60 | # if self.dataIn.type == 'Voltage': | |
61 | # self.dataOut.copy(self.dataIn) |
|
61 | # self.dataOut.copy(self.dataIn) | |
62 | # # No necesita copiar en cada init() los atributos de dataIn |
|
62 | # # No necesita copiar en cada init() los atributos de dataIn | |
63 | # # la copia deberia hacerse por cada nuevo bloque de datos |
|
63 | # # la copia deberia hacerse por cada nuevo bloque de datos | |
64 |
|
64 | |||
65 | def selectChannels(self, channelList): |
|
65 | def selectChannels(self, channelList): | |
66 |
|
66 | |||
67 | channelIndexList = [] |
|
67 | channelIndexList = [] | |
68 |
|
68 | |||
69 | for channel in channelList: |
|
69 | for channel in channelList: | |
70 | index = self.dataOut.channelList.index(channel) |
|
70 | index = self.dataOut.channelList.index(channel) | |
71 | channelIndexList.append(index) |
|
71 | channelIndexList.append(index) | |
72 |
|
72 | |||
73 | self.selectChannelsByIndex(channelIndexList) |
|
73 | self.selectChannelsByIndex(channelIndexList) | |
74 |
|
74 | |||
75 | def selectChannelsByIndex(self, channelIndexList): |
|
75 | def selectChannelsByIndex(self, channelIndexList): | |
76 | """ |
|
76 | """ | |
77 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
77 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
78 |
|
78 | |||
79 | Input: |
|
79 | Input: | |
80 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
80 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
81 |
|
81 | |||
82 | Affected: |
|
82 | Affected: | |
83 | self.dataOut.data |
|
83 | self.dataOut.data | |
84 | self.dataOut.channelIndexList |
|
84 | self.dataOut.channelIndexList | |
85 | self.dataOut.nChannels |
|
85 | self.dataOut.nChannels | |
86 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
86 | self.dataOut.m_ProcessingHeader.totalSpectra | |
87 | self.dataOut.systemHeaderObj.numChannels |
|
87 | self.dataOut.systemHeaderObj.numChannels | |
88 | self.dataOut.m_ProcessingHeader.blockSize |
|
88 | self.dataOut.m_ProcessingHeader.blockSize | |
89 |
|
89 | |||
90 | Return: |
|
90 | Return: | |
91 | None |
|
91 | None | |
92 | """ |
|
92 | """ | |
93 |
|
93 | |||
94 | for channelIndex in channelIndexList: |
|
94 | for channelIndex in channelIndexList: | |
95 | if channelIndex not in self.dataOut.channelIndexList: |
|
95 | if channelIndex not in self.dataOut.channelIndexList: | |
96 | print channelIndexList |
|
96 | print channelIndexList | |
97 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
97 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
98 |
|
98 | |||
99 | # nChannels = len(channelIndexList) |
|
99 | # nChannels = len(channelIndexList) | |
100 |
|
100 | |||
101 | data = self.dataOut.data[channelIndexList,:] |
|
101 | data = self.dataOut.data[channelIndexList,:] | |
102 |
|
102 | |||
103 | self.dataOut.data = data |
|
103 | self.dataOut.data = data | |
104 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
104 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
105 | # self.dataOut.nChannels = nChannels |
|
105 | # self.dataOut.nChannels = nChannels | |
106 |
|
106 | |||
107 | return 1 |
|
107 | return 1 | |
108 |
|
108 | |||
109 | def selectHeights(self, minHei=None, maxHei=None): |
|
109 | def selectHeights(self, minHei=None, maxHei=None): | |
110 | """ |
|
110 | """ | |
111 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
111 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
112 | minHei <= height <= maxHei |
|
112 | minHei <= height <= maxHei | |
113 |
|
113 | |||
114 | Input: |
|
114 | Input: | |
115 | minHei : valor minimo de altura a considerar |
|
115 | minHei : valor minimo de altura a considerar | |
116 | maxHei : valor maximo de altura a considerar |
|
116 | maxHei : valor maximo de altura a considerar | |
117 |
|
117 | |||
118 | Affected: |
|
118 | Affected: | |
119 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
119 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
120 |
|
120 | |||
121 | Return: |
|
121 | Return: | |
122 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
122 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
123 | """ |
|
123 | """ | |
124 |
|
124 | |||
125 | if minHei == None: |
|
125 | if minHei == None: | |
126 | minHei = self.dataOut.heightList[0] |
|
126 | minHei = self.dataOut.heightList[0] | |
127 |
|
127 | |||
128 | if maxHei == None: |
|
128 | if maxHei == None: | |
129 | maxHei = self.dataOut.heightList[-1] |
|
129 | maxHei = self.dataOut.heightList[-1] | |
130 |
|
130 | |||
131 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
131 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
132 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
132 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
133 |
|
133 | |||
134 |
|
134 | |||
135 | if (maxHei > self.dataOut.heightList[-1]): |
|
135 | if (maxHei > self.dataOut.heightList[-1]): | |
136 | maxHei = self.dataOut.heightList[-1] |
|
136 | maxHei = self.dataOut.heightList[-1] | |
137 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
137 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
138 |
|
138 | |||
139 | minIndex = 0 |
|
139 | minIndex = 0 | |
140 | maxIndex = 0 |
|
140 | maxIndex = 0 | |
141 | heights = self.dataOut.heightList |
|
141 | heights = self.dataOut.heightList | |
142 |
|
142 | |||
143 | inda = numpy.where(heights >= minHei) |
|
143 | inda = numpy.where(heights >= minHei) | |
144 | indb = numpy.where(heights <= maxHei) |
|
144 | indb = numpy.where(heights <= maxHei) | |
145 |
|
145 | |||
146 | try: |
|
146 | try: | |
147 | minIndex = inda[0][0] |
|
147 | minIndex = inda[0][0] | |
148 | except: |
|
148 | except: | |
149 | minIndex = 0 |
|
149 | minIndex = 0 | |
150 |
|
150 | |||
151 | try: |
|
151 | try: | |
152 | maxIndex = indb[0][-1] |
|
152 | maxIndex = indb[0][-1] | |
153 | except: |
|
153 | except: | |
154 | maxIndex = len(heights) |
|
154 | maxIndex = len(heights) | |
155 |
|
155 | |||
156 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
156 | self.selectHeightsByIndex(minIndex, maxIndex) | |
157 |
|
157 | |||
158 | return 1 |
|
158 | return 1 | |
159 |
|
159 | |||
160 |
|
160 | |||
161 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
161 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
162 | """ |
|
162 | """ | |
163 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
163 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
164 | minIndex <= index <= maxIndex |
|
164 | minIndex <= index <= maxIndex | |
165 |
|
165 | |||
166 | Input: |
|
166 | Input: | |
167 | minIndex : valor de indice minimo de altura a considerar |
|
167 | minIndex : valor de indice minimo de altura a considerar | |
168 | maxIndex : valor de indice maximo de altura a considerar |
|
168 | maxIndex : valor de indice maximo de altura a considerar | |
169 |
|
169 | |||
170 | Affected: |
|
170 | Affected: | |
171 | self.dataOut.data |
|
171 | self.dataOut.data | |
172 | self.dataOut.heightList |
|
172 | self.dataOut.heightList | |
173 |
|
173 | |||
174 | Return: |
|
174 | Return: | |
175 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
175 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
176 | """ |
|
176 | """ | |
177 |
|
177 | |||
178 | if (minIndex < 0) or (minIndex > maxIndex): |
|
178 | if (minIndex < 0) or (minIndex > maxIndex): | |
179 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
179 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
180 |
|
180 | |||
181 | if (maxIndex >= self.dataOut.nHeights): |
|
181 | if (maxIndex >= self.dataOut.nHeights): | |
182 | maxIndex = self.dataOut.nHeights-1 |
|
182 | maxIndex = self.dataOut.nHeights-1 | |
183 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
183 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
184 |
|
184 | |||
185 | # nHeights = maxIndex - minIndex + 1 |
|
185 | # nHeights = maxIndex - minIndex + 1 | |
186 |
|
186 | |||
187 | #voltage |
|
187 | #voltage | |
188 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
188 | data = self.dataOut.data[:,minIndex:maxIndex+1] | |
189 |
|
189 | |||
190 | # firstHeight = self.dataOut.heightList[minIndex] |
|
190 | # firstHeight = self.dataOut.heightList[minIndex] | |
191 |
|
191 | |||
192 | self.dataOut.data = data |
|
192 | self.dataOut.data = data | |
193 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
193 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
194 |
|
194 | |||
195 | return 1 |
|
195 | return 1 | |
196 |
|
196 | |||
197 |
|
197 | |||
198 | def filterByHeights(self, window, axis=1): |
|
198 | def filterByHeights(self, window, axis=1): | |
199 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
199 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
200 |
|
200 | |||
201 | if window == None: |
|
201 | if window == None: | |
202 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
202 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
203 |
|
203 | |||
204 | newdelta = deltaHeight * window |
|
204 | newdelta = deltaHeight * window | |
205 | r = self.dataOut.data.shape[axis] % window |
|
205 | r = self.dataOut.data.shape[axis] % window | |
206 | if axis == 1: |
|
206 | if axis == 1: | |
207 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[axis]-r] |
|
207 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[axis]-r] | |
208 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[axis]/window,window) |
|
208 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[axis]/window,window) | |
209 | buffer = numpy.sum(buffer,axis+1) |
|
209 | buffer = numpy.sum(buffer,axis+1) | |
210 |
|
210 | |||
211 | elif axis == 2: |
|
211 | elif axis == 2: | |
212 | buffer = self.dataOut.data[:, :, 0:self.dataOut.data.shape[axis]-r] |
|
212 | buffer = self.dataOut.data[:, :, 0:self.dataOut.data.shape[axis]-r] | |
213 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1],self.dataOut.data.shape[axis]/window,window) |
|
213 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1],self.dataOut.data.shape[axis]/window,window) | |
214 | buffer = numpy.sum(buffer,axis+1) |
|
214 | buffer = numpy.sum(buffer,axis+1) | |
215 |
|
215 | |||
216 | else: |
|
216 | else: | |
217 | raise ValueError, "axis value should be 1 or 2, the input value %d is not valid" % (axis) |
|
217 | raise ValueError, "axis value should be 1 or 2, the input value %d is not valid" % (axis) | |
218 |
|
218 | |||
219 | self.dataOut.data = buffer.copy() |
|
219 | self.dataOut.data = buffer.copy() | |
220 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) |
|
220 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) | |
221 | self.dataOut.windowOfFilter = window |
|
221 | self.dataOut.windowOfFilter = window | |
222 |
|
222 | |||
223 | return 1 |
|
223 | return 1 | |
224 |
|
224 | |||
225 | def deFlip(self): |
|
225 | def deFlip(self): | |
226 | self.dataOut.data *= self.flip |
|
226 | self.dataOut.data *= self.flip | |
227 | self.flip *= -1. |
|
227 | self.flip *= -1. | |
228 |
|
228 | |||
229 | def setRadarFrequency(self, frequency=None): |
|
229 | def setRadarFrequency(self, frequency=None): | |
230 | if frequency != None: |
|
230 | if frequency != None: | |
231 | self.dataOut.frequency = frequency |
|
231 | self.dataOut.frequency = frequency | |
232 |
|
232 | |||
233 | return 1 |
|
233 | return 1 | |
234 |
|
234 | |||
235 | class CohInt(Operation): |
|
235 | class CohInt(Operation): | |
236 |
|
236 | |||
237 | isConfig = False |
|
237 | isConfig = False | |
238 |
|
238 | |||
239 | __profIndex = 0 |
|
239 | __profIndex = 0 | |
240 | __withOverapping = False |
|
240 | __withOverapping = False | |
241 |
|
241 | |||
242 | __byTime = False |
|
242 | __byTime = False | |
243 | __initime = None |
|
243 | __initime = None | |
244 | __lastdatatime = None |
|
244 | __lastdatatime = None | |
245 | __integrationtime = None |
|
245 | __integrationtime = None | |
246 |
|
246 | |||
247 | __buffer = None |
|
247 | __buffer = None | |
248 |
|
248 | |||
249 | __dataReady = False |
|
249 | __dataReady = False | |
250 |
|
250 | |||
251 | n = None |
|
251 | n = None | |
252 |
|
252 | |||
253 |
|
253 | |||
254 | def __init__(self): |
|
254 | def __init__(self): | |
255 |
|
255 | |||
256 | Operation.__init__(self) |
|
256 | Operation.__init__(self) | |
257 |
|
257 | |||
258 | # self.isConfig = False |
|
258 | # self.isConfig = False | |
259 |
|
259 | |||
260 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): |
|
260 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): | |
261 | """ |
|
261 | """ | |
262 | Set the parameters of the integration class. |
|
262 | Set the parameters of the integration class. | |
263 |
|
263 | |||
264 | Inputs: |
|
264 | Inputs: | |
265 |
|
265 | |||
266 | n : Number of coherent integrations |
|
266 | n : Number of coherent integrations | |
267 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
267 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
268 | overlapping : |
|
268 | overlapping : | |
269 |
|
269 | |||
270 | """ |
|
270 | """ | |
271 |
|
271 | |||
272 | self.__initime = None |
|
272 | self.__initime = None | |
273 | self.__lastdatatime = 0 |
|
273 | self.__lastdatatime = 0 | |
274 | self.__buffer = None |
|
274 | self.__buffer = None | |
275 | self.__dataReady = False |
|
275 | self.__dataReady = False | |
276 | self.byblock = byblock |
|
276 | self.byblock = byblock | |
277 |
|
277 | |||
278 | if n == None and timeInterval == None: |
|
278 | if n == None and timeInterval == None: | |
279 | raise ValueError, "n or timeInterval should be specified ..." |
|
279 | raise ValueError, "n or timeInterval should be specified ..." | |
280 |
|
280 | |||
281 | if n != None: |
|
281 | if n != None: | |
282 | self.n = n |
|
282 | self.n = n | |
283 | self.__byTime = False |
|
283 | self.__byTime = False | |
284 | else: |
|
284 | else: | |
285 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
285 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
286 | self.n = 9999 |
|
286 | self.n = 9999 | |
287 | self.__byTime = True |
|
287 | self.__byTime = True | |
288 |
|
288 | |||
289 | if overlapping: |
|
289 | if overlapping: | |
290 | self.__withOverapping = True |
|
290 | self.__withOverapping = True | |
291 | self.__buffer = None |
|
291 | self.__buffer = None | |
292 | else: |
|
292 | else: | |
293 | self.__withOverapping = False |
|
293 | self.__withOverapping = False | |
294 | self.__buffer = 0 |
|
294 | self.__buffer = 0 | |
295 |
|
295 | |||
296 | self.__profIndex = 0 |
|
296 | self.__profIndex = 0 | |
297 |
|
297 | |||
298 | def putData(self, data): |
|
298 | def putData(self, data): | |
299 |
|
299 | |||
300 | """ |
|
300 | """ | |
301 | Add a profile to the __buffer and increase in one the __profileIndex |
|
301 | Add a profile to the __buffer and increase in one the __profileIndex | |
302 |
|
302 | |||
303 | """ |
|
303 | """ | |
304 |
|
304 | |||
305 | if not self.__withOverapping: |
|
305 | if not self.__withOverapping: | |
306 | self.__buffer += data.copy() |
|
306 | self.__buffer += data.copy() | |
307 | self.__profIndex += 1 |
|
307 | self.__profIndex += 1 | |
308 | return |
|
308 | return | |
309 |
|
309 | |||
310 | #Overlapping data |
|
310 | #Overlapping data | |
311 | nChannels, nHeis = data.shape |
|
311 | nChannels, nHeis = data.shape | |
312 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
312 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
313 |
|
313 | |||
314 | #If the buffer is empty then it takes the data value |
|
314 | #If the buffer is empty then it takes the data value | |
315 | if self.__buffer == None: |
|
315 | if self.__buffer == None: | |
316 | self.__buffer = data |
|
316 | self.__buffer = data | |
317 | self.__profIndex += 1 |
|
317 | self.__profIndex += 1 | |
318 | return |
|
318 | return | |
319 |
|
319 | |||
320 | #If the buffer length is lower than n then stakcing the data value |
|
320 | #If the buffer length is lower than n then stakcing the data value | |
321 | if self.__profIndex < self.n: |
|
321 | if self.__profIndex < self.n: | |
322 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
322 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
323 | self.__profIndex += 1 |
|
323 | self.__profIndex += 1 | |
324 | return |
|
324 | return | |
325 |
|
325 | |||
326 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
326 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
327 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
327 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
328 | self.__buffer[self.n-1] = data |
|
328 | self.__buffer[self.n-1] = data | |
329 | self.__profIndex = self.n |
|
329 | self.__profIndex = self.n | |
330 | return |
|
330 | return | |
331 |
|
331 | |||
332 |
|
332 | |||
333 | def pushData(self): |
|
333 | def pushData(self): | |
334 | """ |
|
334 | """ | |
335 | Return the sum of the last profiles and the profiles used in the sum. |
|
335 | Return the sum of the last profiles and the profiles used in the sum. | |
336 |
|
336 | |||
337 | Affected: |
|
337 | Affected: | |
338 |
|
338 | |||
339 | self.__profileIndex |
|
339 | self.__profileIndex | |
340 |
|
340 | |||
341 | """ |
|
341 | """ | |
342 |
|
342 | |||
343 | if not self.__withOverapping: |
|
343 | if not self.__withOverapping: | |
344 | data = self.__buffer |
|
344 | data = self.__buffer | |
345 | n = self.__profIndex |
|
345 | n = self.__profIndex | |
346 |
|
346 | |||
347 | self.__buffer = 0 |
|
347 | self.__buffer = 0 | |
348 | self.__profIndex = 0 |
|
348 | self.__profIndex = 0 | |
349 |
|
349 | |||
350 | return data, n |
|
350 | return data, n | |
351 |
|
351 | |||
352 | #Integration with Overlapping |
|
352 | #Integration with Overlapping | |
353 | data = numpy.sum(self.__buffer, axis=0) |
|
353 | data = numpy.sum(self.__buffer, axis=0) | |
354 | n = self.__profIndex |
|
354 | n = self.__profIndex | |
355 |
|
355 | |||
356 | return data, n |
|
356 | return data, n | |
357 |
|
357 | |||
358 | def byProfiles(self, data): |
|
358 | def byProfiles(self, data): | |
359 |
|
359 | |||
360 | self.__dataReady = False |
|
360 | self.__dataReady = False | |
361 | avgdata = None |
|
361 | avgdata = None | |
362 | # n = None |
|
362 | # n = None | |
363 |
|
363 | |||
364 | self.putData(data) |
|
364 | self.putData(data) | |
365 |
|
365 | |||
366 | if self.__profIndex == self.n: |
|
366 | if self.__profIndex == self.n: | |
367 |
|
367 | |||
368 | avgdata, n = self.pushData() |
|
368 | avgdata, n = self.pushData() | |
369 | self.__dataReady = True |
|
369 | self.__dataReady = True | |
370 |
|
370 | |||
371 | return avgdata |
|
371 | return avgdata | |
372 |
|
372 | |||
373 | def byTime(self, data, datatime): |
|
373 | def byTime(self, data, datatime): | |
374 |
|
374 | |||
375 | self.__dataReady = False |
|
375 | self.__dataReady = False | |
376 | avgdata = None |
|
376 | avgdata = None | |
377 | n = None |
|
377 | n = None | |
378 |
|
378 | |||
379 | self.putData(data) |
|
379 | self.putData(data) | |
380 |
|
380 | |||
381 | if (datatime - self.__initime) >= self.__integrationtime: |
|
381 | if (datatime - self.__initime) >= self.__integrationtime: | |
382 | avgdata, n = self.pushData() |
|
382 | avgdata, n = self.pushData() | |
383 | self.n = n |
|
383 | self.n = n | |
384 | self.__dataReady = True |
|
384 | self.__dataReady = True | |
385 |
|
385 | |||
386 | return avgdata |
|
386 | return avgdata | |
387 |
|
387 | |||
388 | def integrate(self, data, datatime=None): |
|
388 | def integrate(self, data, datatime=None): | |
389 |
|
389 | |||
390 | if self.__initime == None: |
|
390 | if self.__initime == None: | |
391 | self.__initime = datatime |
|
391 | self.__initime = datatime | |
392 |
|
392 | |||
393 | if self.__byTime: |
|
393 | if self.__byTime: | |
394 | avgdata = self.byTime(data, datatime) |
|
394 | avgdata = self.byTime(data, datatime) | |
395 | else: |
|
395 | else: | |
396 | avgdata = self.byProfiles(data) |
|
396 | avgdata = self.byProfiles(data) | |
397 |
|
397 | |||
398 |
|
398 | |||
399 | self.__lastdatatime = datatime |
|
399 | self.__lastdatatime = datatime | |
400 |
|
400 | |||
401 | if avgdata == None: |
|
401 | if avgdata == None: | |
402 | return None, None |
|
402 | return None, None | |
403 |
|
403 | |||
404 | avgdatatime = self.__initime |
|
404 | avgdatatime = self.__initime | |
405 |
|
405 | |||
406 | deltatime = datatime -self.__lastdatatime |
|
406 | deltatime = datatime -self.__lastdatatime | |
407 |
|
407 | |||
408 | if not self.__withOverapping: |
|
408 | if not self.__withOverapping: | |
409 | self.__initime = datatime |
|
409 | self.__initime = datatime | |
410 | else: |
|
410 | else: | |
411 | self.__initime += deltatime |
|
411 | self.__initime += deltatime | |
412 |
|
412 | |||
413 | return avgdata, avgdatatime |
|
413 | return avgdata, avgdatatime | |
414 |
|
414 | |||
415 | def integrateByBlock(self, dataOut): |
|
415 | def integrateByBlock(self, dataOut): | |
416 | times = int(dataOut.data.shape[1]/self.n) |
|
416 | times = int(dataOut.data.shape[1]/self.n) | |
417 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
417 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
418 |
|
418 | |||
419 | id_min = 0 |
|
419 | id_min = 0 | |
420 | id_max = self.n |
|
420 | id_max = self.n | |
421 |
|
421 | |||
422 | for i in range(times): |
|
422 | for i in range(times): | |
423 | junk = dataOut.data[:,id_min:id_max,:] |
|
423 | junk = dataOut.data[:,id_min:id_max,:] | |
424 | avgdata[:,i,:] = junk.sum(axis=1) |
|
424 | avgdata[:,i,:] = junk.sum(axis=1) | |
425 | id_min += self.n |
|
425 | id_min += self.n | |
426 | id_max += self.n |
|
426 | id_max += self.n | |
427 |
|
427 | |||
428 | timeInterval = dataOut.ippSeconds*self.n |
|
428 | timeInterval = dataOut.ippSeconds*self.n | |
429 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
429 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
430 | self.__dataReady = True |
|
430 | self.__dataReady = True | |
431 | return avgdata, avgdatatime |
|
431 | return avgdata, avgdatatime | |
432 |
|
432 | |||
433 | def run(self, dataOut, **kwargs): |
|
433 | def run(self, dataOut, **kwargs): | |
434 |
|
434 | |||
435 | if not self.isConfig: |
|
435 | if not self.isConfig: | |
436 | self.setup(**kwargs) |
|
436 | self.setup(**kwargs) | |
437 | self.isConfig = True |
|
437 | self.isConfig = True | |
438 |
|
438 | |||
439 | if self.byblock: |
|
439 | if self.byblock: | |
440 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
440 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
441 | else: |
|
441 | else: | |
442 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
442 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
443 |
|
443 | |||
444 | # dataOut.timeInterval *= n |
|
444 | # dataOut.timeInterval *= n | |
445 | dataOut.flagNoData = True |
|
445 | dataOut.flagNoData = True | |
446 |
|
446 | |||
447 | if self.__dataReady: |
|
447 | if self.__dataReady: | |
448 | dataOut.data = avgdata |
|
448 | dataOut.data = avgdata | |
449 | dataOut.nCohInt *= self.n |
|
449 | dataOut.nCohInt *= self.n | |
450 | dataOut.utctime = avgdatatime |
|
450 | dataOut.utctime = avgdatatime | |
451 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
451 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
452 | dataOut.flagNoData = False |
|
452 | dataOut.flagNoData = False | |
453 |
|
453 | |||
454 | class Decoder(Operation): |
|
454 | class Decoder(Operation): | |
455 |
|
455 | |||
456 | isConfig = False |
|
456 | isConfig = False | |
457 | __profIndex = 0 |
|
457 | __profIndex = 0 | |
458 |
|
458 | |||
459 | code = None |
|
459 | code = None | |
460 |
|
460 | |||
461 | nCode = None |
|
461 | nCode = None | |
462 | nBaud = None |
|
462 | nBaud = None | |
463 |
|
463 | |||
464 |
|
464 | |||
465 | def __init__(self): |
|
465 | def __init__(self): | |
466 |
|
466 | |||
467 | Operation.__init__(self) |
|
467 | Operation.__init__(self) | |
468 |
|
468 | |||
469 | self.times = None |
|
469 | self.times = None | |
470 | self.osamp = None |
|
470 | self.osamp = None | |
471 | self.__setValues = False |
|
471 | self.__setValues = False | |
472 | # self.isConfig = False |
|
472 | # self.isConfig = False | |
473 |
|
473 | |||
474 | def setup(self, code, shape, times, osamp): |
|
474 | def setup(self, code, shape, times, osamp): | |
475 |
|
475 | |||
476 | self.__profIndex = 0 |
|
476 | self.__profIndex = 0 | |
477 |
|
477 | |||
478 | self.code = code |
|
478 | self.code = code | |
479 |
|
479 | |||
480 | self.nCode = len(code) |
|
480 | self.nCode = len(code) | |
481 | self.nBaud = len(code[0]) |
|
481 | self.nBaud = len(code[0]) | |
482 |
|
482 | |||
483 | if times != None: |
|
483 | if times != None: | |
484 | self.times = times |
|
484 | self.times = times | |
485 |
|
485 | |||
486 | if ((osamp != None) and (osamp >1)): |
|
486 | if ((osamp != None) and (osamp >1)): | |
487 | self.osamp = osamp |
|
487 | self.osamp = osamp | |
488 | self.code = numpy.repeat(code, repeats=self.osamp,axis=1) |
|
488 | self.code = numpy.repeat(code, repeats=self.osamp,axis=1) | |
489 | self.nBaud = self.nBaud*self.osamp |
|
489 | self.nBaud = self.nBaud*self.osamp | |
490 |
|
490 | |||
491 | if len(shape) == 2: |
|
491 | if len(shape) == 2: | |
492 | self.__nChannels, self.__nHeis = shape |
|
492 | self.__nChannels, self.__nHeis = shape | |
493 |
|
493 | |||
494 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
494 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
495 |
|
495 | |||
496 | __codeBuffer[:,0:self.nBaud] = self.code |
|
496 | __codeBuffer[:,0:self.nBaud] = self.code | |
497 |
|
497 | |||
498 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
498 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
499 |
|
499 | |||
500 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
500 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
501 |
|
501 | |||
502 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
502 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
503 | else: |
|
503 | else: | |
504 | self.__nChannels, self.__nProfiles, self.__nHeis = shape |
|
504 | self.__nChannels, self.__nProfiles, self.__nHeis = shape | |
505 |
|
505 | |||
506 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
506 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
507 |
|
507 | |||
508 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
508 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
509 |
|
509 | |||
510 |
|
510 | |||
511 |
|
511 | |||
512 | def convolutionInFreq(self, data): |
|
512 | def convolutionInFreq(self, data): | |
513 |
|
513 | |||
514 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
514 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
515 |
|
515 | |||
516 | fft_data = numpy.fft.fft(data, axis=1) |
|
516 | fft_data = numpy.fft.fft(data, axis=1) | |
517 |
|
517 | |||
518 | conv = fft_data*fft_code |
|
518 | conv = fft_data*fft_code | |
519 |
|
519 | |||
520 | data = numpy.fft.ifft(conv,axis=1) |
|
520 | data = numpy.fft.ifft(conv,axis=1) | |
521 |
|
521 | |||
522 | datadec = data[:,:-self.nBaud+1] |
|
522 | datadec = data[:,:-self.nBaud+1] | |
523 |
|
523 | |||
524 | return datadec |
|
524 | return datadec | |
525 |
|
525 | |||
526 | def convolutionInFreqOpt(self, data): |
|
526 | def convolutionInFreqOpt(self, data): | |
527 |
|
527 | |||
528 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
528 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
529 |
|
529 | |||
530 | data = cfunctions.decoder(fft_code, data) |
|
530 | data = cfunctions.decoder(fft_code, data) | |
531 |
|
531 | |||
532 | datadec = data[:,:-self.nBaud+1] |
|
532 | datadec = data[:,:-self.nBaud+1] | |
533 |
|
533 | |||
534 | return datadec |
|
534 | return datadec | |
535 |
|
535 | |||
536 | def convolutionInTime(self, data): |
|
536 | def convolutionInTime(self, data): | |
537 |
|
537 | |||
538 | code = self.code[self.__profIndex] |
|
538 | code = self.code[self.__profIndex] | |
539 |
|
539 | |||
540 | for i in range(self.__nChannels): |
|
540 | for i in range(self.__nChannels): | |
541 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') |
|
541 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') | |
542 |
|
542 | |||
543 | return self.datadecTime |
|
543 | return self.datadecTime | |
544 |
|
544 | |||
545 | def convolutionByBlockInTime(self, data): |
|
545 | def convolutionByBlockInTime(self, data): | |
546 | junk = numpy.lib.stride_tricks.as_strided(self.code, (self.times, self.code.size), (0, self.code.itemsize)) |
|
546 | junk = numpy.lib.stride_tricks.as_strided(self.code, (self.times, self.code.size), (0, self.code.itemsize)) | |
547 | junk = junk.flatten() |
|
547 | junk = junk.flatten() | |
548 | code_block = numpy.reshape(junk, (self.nCode*self.times,self.nBaud)) |
|
548 | code_block = numpy.reshape(junk, (self.nCode*self.times,self.nBaud)) | |
549 |
|
549 | |||
550 | for i in range(self.__nChannels): |
|
550 | for i in range(self.__nChannels): | |
551 | for j in range(self.__nProfiles): |
|
551 | for j in range(self.__nProfiles): | |
552 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='valid') |
|
552 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='valid') | |
553 |
|
553 | |||
554 | return self.datadecTime |
|
554 | return self.datadecTime | |
555 |
|
555 | |||
556 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None): |
|
556 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None): | |
557 |
|
557 | |||
558 | if code == None: |
|
558 | if code == None: | |
559 | code = dataOut.code |
|
559 | code = dataOut.code | |
560 | else: |
|
560 | else: | |
561 | code = numpy.array(code).reshape(nCode,nBaud) |
|
561 | code = numpy.array(code).reshape(nCode,nBaud) | |
562 |
|
562 | |||
563 |
|
563 | |||
564 |
|
564 | |||
565 | if not self.isConfig: |
|
565 | if not self.isConfig: | |
566 |
|
566 | |||
567 | self.setup(code, dataOut.data.shape, times, osamp) |
|
567 | self.setup(code, dataOut.data.shape, times, osamp) | |
568 |
|
568 | |||
569 | dataOut.code = code |
|
569 | dataOut.code = code | |
570 | dataOut.nCode = nCode |
|
570 | dataOut.nCode = nCode | |
571 | dataOut.nBaud = nBaud |
|
571 | dataOut.nBaud = nBaud | |
572 | dataOut.radarControllerHeaderObj.code = code |
|
572 | dataOut.radarControllerHeaderObj.code = code | |
573 | dataOut.radarControllerHeaderObj.nCode = nCode |
|
573 | dataOut.radarControllerHeaderObj.nCode = nCode | |
574 | dataOut.radarControllerHeaderObj.nBaud = nBaud |
|
574 | dataOut.radarControllerHeaderObj.nBaud = nBaud | |
575 |
|
575 | |||
576 | self.isConfig = True |
|
576 | self.isConfig = True | |
577 |
|
577 | |||
578 | if mode == 0: |
|
578 | if mode == 0: | |
579 | datadec = self.convolutionInTime(dataOut.data) |
|
579 | datadec = self.convolutionInTime(dataOut.data) | |
580 |
|
580 | |||
581 | if mode == 1: |
|
581 | if mode == 1: | |
582 | datadec = self.convolutionInFreq(dataOut.data) |
|
582 | datadec = self.convolutionInFreq(dataOut.data) | |
583 |
|
583 | |||
584 | if mode == 2: |
|
584 | if mode == 2: | |
585 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
585 | datadec = self.convolutionInFreqOpt(dataOut.data) | |
586 |
|
586 | |||
587 | if mode == 3: |
|
587 | if mode == 3: | |
588 | datadec = self.convolutionByBlockInTime(dataOut.data) |
|
588 | datadec = self.convolutionByBlockInTime(dataOut.data) | |
589 |
|
589 | |||
590 | if not(self.__setValues): |
|
590 | if not(self.__setValues): | |
591 | dataOut.code = self.code |
|
591 | dataOut.code = self.code | |
592 | dataOut.nCode = self.nCode |
|
592 | dataOut.nCode = self.nCode | |
593 | dataOut.nBaud = self.nBaud |
|
593 | dataOut.nBaud = self.nBaud | |
594 | dataOut.radarControllerHeaderObj.code = self.code |
|
594 | dataOut.radarControllerHeaderObj.code = self.code | |
595 | dataOut.radarControllerHeaderObj.nCode = self.nCode |
|
595 | dataOut.radarControllerHeaderObj.nCode = self.nCode | |
596 | dataOut.radarControllerHeaderObj.nBaud = self.nBaud |
|
596 | dataOut.radarControllerHeaderObj.nBaud = self.nBaud | |
597 | self.__setValues = True |
|
597 | self.__setValues = True | |
598 |
|
598 | |||
599 | dataOut.data = datadec |
|
599 | dataOut.data = datadec | |
600 |
|
600 | |||
601 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
601 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] | |
602 |
|
602 | |||
603 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada |
|
603 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada | |
604 |
|
604 | |||
605 | if self.__profIndex == self.nCode-1: |
|
605 | if self.__profIndex == self.nCode-1: | |
606 | self.__profIndex = 0 |
|
606 | self.__profIndex = 0 | |
607 | return 1 |
|
607 | return 1 | |
608 |
|
608 | |||
609 | self.__profIndex += 1 |
|
609 | self.__profIndex += 1 | |
610 |
|
610 | |||
611 | return 1 |
|
611 | return 1 | |
612 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
612 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
613 |
|
613 | |||
614 |
|
614 | |||
615 | class ProfileConcat(Operation): |
|
615 | class ProfileConcat(Operation): | |
616 |
|
616 | |||
617 | isConfig = False |
|
617 | isConfig = False | |
618 | buffer = None |
|
618 | buffer = None | |
619 |
|
619 | |||
620 | def __init__(self): |
|
620 | def __init__(self): | |
621 |
|
621 | |||
622 | Operation.__init__(self) |
|
622 | Operation.__init__(self) | |
623 | self.profileIndex = 0 |
|
623 | self.profileIndex = 0 | |
624 |
|
624 | |||
625 | def reset(self): |
|
625 | def reset(self): | |
626 | self.buffer = numpy.zeros_like(self.buffer) |
|
626 | self.buffer = numpy.zeros_like(self.buffer) | |
627 | self.start_index = 0 |
|
627 | self.start_index = 0 | |
628 | self.times = 1 |
|
628 | self.times = 1 | |
629 |
|
629 | |||
630 | def setup(self, data, m, n=1): |
|
630 | def setup(self, data, m, n=1): | |
631 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
631 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
632 | self.profiles = data.shape[1] |
|
632 | self.profiles = data.shape[1] | |
633 | self.start_index = 0 |
|
633 | self.start_index = 0 | |
634 | self.times = 1 |
|
634 | self.times = 1 | |
635 |
|
635 | |||
636 | def concat(self, data): |
|
636 | def concat(self, data): | |
637 |
|
637 | |||
638 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() |
|
638 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() | |
639 | self.start_index = self.start_index + self.profiles |
|
639 | self.start_index = self.start_index + self.profiles | |
640 |
|
640 | |||
641 | def run(self, dataOut, m): |
|
641 | def run(self, dataOut, m): | |
642 |
|
642 | |||
643 | dataOut.flagNoData = True |
|
643 | dataOut.flagNoData = True | |
644 |
|
644 | |||
645 | if not self.isConfig: |
|
645 | if not self.isConfig: | |
646 | self.setup(dataOut.data, m, 1) |
|
646 | self.setup(dataOut.data, m, 1) | |
647 | self.isConfig = True |
|
647 | self.isConfig = True | |
648 |
|
648 | |||
649 | self.concat(dataOut.data) |
|
649 | self.concat(dataOut.data) | |
650 | self.times += 1 |
|
650 | self.times += 1 | |
651 | if self.times > m: |
|
651 | if self.times > m: | |
652 | dataOut.data = self.buffer |
|
652 | dataOut.data = self.buffer | |
653 | self.reset() |
|
653 | self.reset() | |
654 | dataOut.flagNoData = False |
|
654 | dataOut.flagNoData = False | |
655 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
655 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
656 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
656 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
657 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 |
|
657 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 | |
658 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
658 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
659 |
|
659 | |||
660 | class ProfileSelector(Operation): |
|
660 | class ProfileSelector(Operation): | |
661 |
|
661 | |||
662 | profileIndex = None |
|
662 | profileIndex = None | |
663 | # Tamanho total de los perfiles |
|
663 | # Tamanho total de los perfiles | |
664 | nProfiles = None |
|
664 | nProfiles = None | |
665 |
|
665 | |||
666 | def __init__(self): |
|
666 | def __init__(self): | |
667 |
|
667 | |||
668 | Operation.__init__(self) |
|
668 | Operation.__init__(self) | |
669 | self.profileIndex = 0 |
|
669 | self.profileIndex = 0 | |
670 |
|
670 | |||
671 | def incIndex(self): |
|
671 | def incIndex(self): | |
672 | self.profileIndex += 1 |
|
672 | self.profileIndex += 1 | |
673 |
|
673 | |||
674 | if self.profileIndex >= self.nProfiles: |
|
674 | if self.profileIndex >= self.nProfiles: | |
675 | self.profileIndex = 0 |
|
675 | self.profileIndex = 0 | |
676 |
|
676 | |||
677 | def isProfileInRange(self, minIndex, maxIndex): |
|
677 | def isProfileInRange(self, minIndex, maxIndex): | |
678 |
|
678 | |||
679 | if self.profileIndex < minIndex: |
|
679 | if self.profileIndex < minIndex: | |
680 | return False |
|
680 | return False | |
681 |
|
681 | |||
682 | if self.profileIndex > maxIndex: |
|
682 | if self.profileIndex > maxIndex: | |
683 | return False |
|
683 | return False | |
684 |
|
684 | |||
685 | return True |
|
685 | return True | |
686 |
|
686 | |||
687 | def isProfileInList(self, profileList): |
|
687 | def isProfileInList(self, profileList): | |
688 |
|
688 | |||
689 | if self.profileIndex not in profileList: |
|
689 | if self.profileIndex not in profileList: | |
690 | return False |
|
690 | return False | |
691 |
|
691 | |||
692 | return True |
|
692 | return True | |
693 |
|
693 | |||
694 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False): |
|
694 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False): | |
695 |
|
695 | |||
696 | dataOut.flagNoData = True |
|
696 | dataOut.flagNoData = True | |
697 | self.nProfiles = dataOut.nProfiles |
|
697 | self.nProfiles = dataOut.nProfiles | |
698 |
|
698 | |||
699 | if byblock: |
|
699 | if byblock: | |
700 |
|
700 | |||
701 | if profileList != None: |
|
701 | if profileList != None: | |
702 | dataOut.data = dataOut.data[:,profileList,:] |
|
702 | dataOut.data = dataOut.data[:,profileList,:] | |
703 | pass |
|
703 | pass | |
704 | else: |
|
704 | else: | |
705 | pmin = profileRangeList[0] |
|
705 | pmin = profileRangeList[0] | |
706 | pmax = profileRangeList[1] |
|
706 | pmax = profileRangeList[1] | |
707 | dataOut.data = dataOut.data[:,pmin:pmax+1,:] |
|
707 | dataOut.data = dataOut.data[:,pmin:pmax+1,:] | |
708 | dataOut.flagNoData = False |
|
708 | dataOut.flagNoData = False | |
709 | self.profileIndex = 0 |
|
709 | self.profileIndex = 0 | |
710 | return 1 |
|
710 | return 1 | |
711 |
|
711 | |||
712 | if profileList != None: |
|
712 | if profileList != None: | |
713 | if self.isProfileInList(profileList): |
|
713 | if self.isProfileInList(profileList): | |
714 | dataOut.flagNoData = False |
|
714 | dataOut.flagNoData = False | |
715 |
|
715 | |||
716 | self.incIndex() |
|
716 | self.incIndex() | |
717 | return 1 |
|
717 | return 1 | |
718 |
|
718 | |||
719 |
|
719 | |||
720 | elif profileRangeList != None: |
|
720 | elif profileRangeList != None: | |
721 | minIndex = profileRangeList[0] |
|
721 | minIndex = profileRangeList[0] | |
722 | maxIndex = profileRangeList[1] |
|
722 | maxIndex = profileRangeList[1] | |
723 | if self.isProfileInRange(minIndex, maxIndex): |
|
723 | if self.isProfileInRange(minIndex, maxIndex): | |
724 | dataOut.flagNoData = False |
|
724 | dataOut.flagNoData = False | |
725 |
|
725 | |||
726 | self.incIndex() |
|
726 | self.incIndex() | |
727 | return 1 |
|
727 | return 1 | |
728 | elif beam != None: #beam is only for AMISR data |
|
728 | elif beam != None: #beam is only for AMISR data | |
729 | if self.isProfileInList(dataOut.beamRangeDict[beam]): |
|
729 | if self.isProfileInList(dataOut.beamRangeDict[beam]): | |
730 | dataOut.flagNoData = False |
|
730 | dataOut.flagNoData = False | |
731 |
|
731 | |||
732 | self.incIndex() |
|
732 | self.incIndex() | |
733 | return 1 |
|
733 | return 1 | |
734 |
|
734 | |||
735 | else: |
|
735 | else: | |
736 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
736 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
737 |
|
737 | |||
738 | return 0 |
|
738 | return 0 | |
739 |
|
739 | |||
740 |
|
740 | |||
741 |
|
741 | |||
742 | class Reshaper(Operation): |
|
742 | class Reshaper(Operation): | |
743 | def __init__(self): |
|
743 | def __init__(self): | |
744 | Operation.__init__(self) |
|
744 | Operation.__init__(self) | |
745 | self.updateNewHeights = False |
|
745 | self.updateNewHeights = False | |
746 |
|
746 | |||
747 | def run(self, dataOut, shape): |
|
747 | def run(self, dataOut, shape): | |
748 | shape_tuple = tuple(shape) |
|
748 | shape_tuple = tuple(shape) | |
749 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
749 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
750 | dataOut.flagNoData = False |
|
750 | dataOut.flagNoData = False | |
751 |
|
751 | |||
752 | if not(self.updateNewHeights): |
|
752 | if not(self.updateNewHeights): | |
753 | old_nheights = dataOut.nHeights |
|
753 | old_nheights = dataOut.nHeights | |
754 | new_nheights = dataOut.data.shape[2] |
|
754 | new_nheights = dataOut.data.shape[2] | |
755 | factor = new_nheights / old_nheights |
|
755 | factor = new_nheights / old_nheights | |
756 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
756 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
757 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor |
|
757 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor | |
758 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) No newline at end of file |
|
758 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
General Comments 0
You need to be logged in to leave comments.
Login now