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