The requested changes are too big and content was truncated. Show full diff
@@ -1,660 +1,662 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Set 9, 2015 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 Karim Kuyeng |
|
5 | ||
|
6 | @update: 2021, Joab Apaza | |
|
5 | 7 | ''' |
|
6 | 8 | |
|
7 | 9 | import os |
|
8 | 10 | import sys |
|
9 | 11 | import glob |
|
10 | 12 | import fnmatch |
|
11 | 13 | import datetime |
|
12 | 14 | import time |
|
13 | 15 | import re |
|
14 | 16 | import h5py |
|
15 | 17 | import numpy |
|
16 | 18 | |
|
17 | 19 | try: |
|
18 | 20 | from gevent import sleep |
|
19 | 21 | except: |
|
20 | 22 | from time import sleep |
|
21 | 23 | |
|
22 | 24 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader |
|
23 | 25 | from schainpy.model.data.jrodata import Voltage |
|
24 | 26 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
25 | 27 | from numpy import imag |
|
26 | 28 | |
|
27 | 29 | |
|
28 | 30 | class AMISRReader(ProcessingUnit): |
|
29 | 31 | ''' |
|
30 | 32 | classdocs |
|
31 | 33 | ''' |
|
32 | 34 | |
|
33 | 35 | def __init__(self): |
|
34 | 36 | ''' |
|
35 | 37 | Constructor |
|
36 | 38 | ''' |
|
37 | 39 | |
|
38 | 40 | ProcessingUnit.__init__(self) |
|
39 | 41 | |
|
40 | 42 | self.set = None |
|
41 | 43 | self.subset = None |
|
42 | 44 | self.extension_file = '.h5' |
|
43 | 45 | self.dtc_str = 'dtc' |
|
44 | 46 | self.dtc_id = 0 |
|
45 | 47 | self.status = True |
|
46 | 48 | self.isConfig = False |
|
47 | 49 | self.dirnameList = [] |
|
48 | 50 | self.filenameList = [] |
|
49 | 51 | self.fileIndex = None |
|
50 | 52 | self.flagNoMoreFiles = False |
|
51 | 53 | self.flagIsNewFile = 0 |
|
52 | 54 | self.filename = '' |
|
53 | 55 | self.amisrFilePointer = None |
|
54 | 56 | self.realBeamCode = [] |
|
55 | 57 | |
|
56 | 58 | self.dataShape = None |
|
57 | 59 | |
|
58 | 60 | |
|
59 | 61 | |
|
60 | 62 | self.profileIndex = 0 |
|
61 | 63 | |
|
62 | 64 | |
|
63 | 65 | self.beamCodeByFrame = None |
|
64 | 66 | self.radacTimeByFrame = None |
|
65 | 67 | |
|
66 | 68 | self.dataset = None |
|
67 | 69 | |
|
68 | 70 | |
|
69 | 71 | |
|
70 | 72 | |
|
71 | 73 | self.__firstFile = True |
|
72 | 74 | |
|
73 | 75 | self.buffer = None |
|
74 | 76 | |
|
75 | 77 | |
|
76 | 78 | self.timezone = 'ut' |
|
77 | 79 | |
|
78 | 80 | self.__waitForNewFile = 20 |
|
79 | 81 | self.__filename_online = None |
|
80 | 82 | #Is really necessary create the output object in the initializer |
|
81 | 83 | self.dataOut = Voltage() |
|
82 | 84 | self.dataOut.error=False |
|
83 | 85 | |
|
84 | 86 | |
|
85 | 87 | def setup(self,path=None, |
|
86 | 88 | startDate=None, |
|
87 | 89 | endDate=None, |
|
88 | 90 | startTime=None, |
|
89 | 91 | endTime=None, |
|
90 | 92 | walk=True, |
|
91 | 93 | timezone='ut', |
|
92 | 94 | all=0, |
|
93 | 95 | code = None, |
|
94 | 96 | nCode = 0, |
|
95 | 97 | nBaud = 0, |
|
96 | 98 | online=False): |
|
97 | 99 | |
|
98 | 100 | |
|
99 | 101 | |
|
100 | 102 | self.timezone = timezone |
|
101 | 103 | self.all = all |
|
102 | 104 | self.online = online |
|
103 | 105 | |
|
104 | 106 | self.code = code |
|
105 | 107 | self.nCode = int(nCode) |
|
106 | 108 | self.nBaud = int(nBaud) |
|
107 | 109 | |
|
108 | 110 | |
|
109 | 111 | |
|
110 | 112 | #self.findFiles() |
|
111 | 113 | if not(online): |
|
112 | 114 | #Busqueda de archivos offline |
|
113 | 115 | self.searchFilesOffLine(path, startDate, endDate, startTime, endTime, walk) |
|
114 | 116 | else: |
|
115 | 117 | self.searchFilesOnLine(path, startDate, endDate, startTime,endTime,walk) |
|
116 | 118 | |
|
117 | 119 | if not(self.filenameList): |
|
118 | 120 | print("There is no files into the folder: %s"%(path)) |
|
119 | 121 | sys.exit() |
|
120 | 122 | |
|
121 | 123 | self.fileIndex = 0 |
|
122 | 124 | |
|
123 | 125 | self.readNextFile(online) |
|
124 | 126 | |
|
125 | 127 | ''' |
|
126 | 128 | Add code |
|
127 | 129 | ''' |
|
128 | 130 | self.isConfig = True |
|
129 | 131 | # print("Setup Done") |
|
130 | 132 | pass |
|
131 | 133 | |
|
132 | 134 | |
|
133 | 135 | def readAMISRHeader(self,fp): |
|
134 | 136 | |
|
135 | 137 | if self.isConfig and (not self.flagNoMoreFiles): |
|
136 | 138 | newShape = fp.get('Raw11/Data/Samples/Data').shape[1:] |
|
137 | 139 | if self.dataShape != newShape and newShape != None: |
|
138 | 140 | print("\nNEW FILE HAS A DIFFERENT SHAPE") |
|
139 | 141 | print(self.dataShape,newShape,"\n") |
|
140 | 142 | return 0 |
|
141 | 143 | else: |
|
142 | 144 | self.dataShape = fp.get('Raw11/Data/Samples/Data').shape[1:] |
|
143 | 145 | |
|
144 | 146 | |
|
145 | 147 | header = 'Raw11/Data/RadacHeader' |
|
146 | 148 | self.beamCodeByPulse = fp.get(header+'/BeamCode') # LIST OF BEAMS PER PROFILE, TO BE USED ON REARRANGE |
|
147 | 149 | if (self.startDate> datetime.date(2021, 7, 15)): #Se cambió la forma de extracción de Apuntes el 17 |
|
148 | 150 | self.beamcodeFile = fp['Setup/Beamcodefile'][()].decode() |
|
149 | 151 | self.trueBeams = self.beamcodeFile.split("\n") |
|
150 | 152 | self.trueBeams.pop()#remove last |
|
151 | 153 | [self.realBeamCode.append(x) for x in self.trueBeams if x not in self.realBeamCode] |
|
152 | 154 | self.beamCode = [int(x, 16) for x in self.realBeamCode] |
|
153 | 155 | else: |
|
154 | 156 | _beamCode= fp.get('Raw11/Data/Beamcodes') #se usa la manera previa al cambio de apuntes |
|
155 | 157 | self.beamCode = _beamCode[0,:] |
|
156 | 158 | |
|
157 | 159 | |
|
158 | 160 | #self.code = fp.get(header+'/Code') # NOT USE FOR THIS |
|
159 | 161 | self.frameCount = fp.get(header+'/FrameCount')# NOT USE FOR THIS |
|
160 | 162 | self.modeGroup = fp.get(header+'/ModeGroup')# NOT USE FOR THIS |
|
161 | 163 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse')# TO GET NSA OR USING DATA FOR THAT |
|
162 | 164 | self.pulseCount = fp.get(header+'/PulseCount')# NOT USE FOR THIS |
|
163 | 165 | self.radacTime = fp.get(header+'/RadacTime')# 1st TIME ON FILE ANDE CALCULATE THE REST WITH IPP*nindexprofile |
|
164 | 166 | self.timeCount = fp.get(header+'/TimeCount')# NOT USE FOR THIS |
|
165 | 167 | self.timeStatus = fp.get(header+'/TimeStatus')# NOT USE FOR THIS |
|
166 | 168 | self.rangeFromFile = fp.get('Raw11/Data/Samples/Range') |
|
167 | 169 | self.frequency = fp.get('Rx/Frequency') |
|
168 | 170 | txAus = fp.get('Raw11/Data/Pulsewidth') |
|
169 | 171 | |
|
170 | 172 | |
|
171 | 173 | self.nblocks = self.pulseCount.shape[0] #nblocks |
|
172 | 174 | |
|
173 | 175 | self.nprofiles = self.pulseCount.shape[1] #nprofile |
|
174 | 176 | self.nsa = self.nsamplesPulse[0,0] #ngates |
|
175 | 177 | self.nchannels = len(self.beamCode) |
|
176 | 178 | self.ippSeconds = (self.radacTime[0][1] -self.radacTime[0][0]) #Ipp in seconds |
|
177 | 179 | #self.__waitForNewFile = self.nblocks # wait depending on the number of blocks since each block is 1 sec |
|
178 | 180 | self.__waitForNewFile = self.nblocks * self.nprofiles * self.ippSeconds # wait until new file is created |
|
179 | 181 | |
|
180 | 182 | #filling radar controller header parameters |
|
181 | 183 | self.__ippKm = self.ippSeconds *.15*1e6 # in km |
|
182 | 184 | self.__txA = (txAus.value)*.15 #(ipp[us]*.15km/1us) in km |
|
183 | 185 | self.__txB = 0 |
|
184 | 186 | nWindows=1 |
|
185 | 187 | self.__nSamples = self.nsa |
|
186 | 188 | self.__firstHeight = self.rangeFromFile[0][0]/1000 #in km |
|
187 | 189 | self.__deltaHeight = (self.rangeFromFile[0][1] - self.rangeFromFile[0][0])/1000 |
|
188 | 190 | |
|
189 | 191 | #for now until understand why the code saved is different (code included even though code not in tuf file) |
|
190 | 192 | #self.__codeType = 0 |
|
191 | 193 | # self.__nCode = None |
|
192 | 194 | # self.__nBaud = None |
|
193 | 195 | self.__code = self.code |
|
194 | 196 | self.__codeType = 0 |
|
195 | 197 | if self.code != None: |
|
196 | 198 | self.__codeType = 1 |
|
197 | 199 | self.__nCode = self.nCode |
|
198 | 200 | self.__nBaud = self.nBaud |
|
199 | 201 | #self.__code = 0 |
|
200 | 202 | |
|
201 | 203 | #filling system header parameters |
|
202 | 204 | self.__nSamples = self.nsa |
|
203 | 205 | self.newProfiles = self.nprofiles/self.nchannels |
|
204 | 206 | self.__channelList = list(range(self.nchannels)) |
|
205 | 207 | |
|
206 | 208 | self.__frequency = self.frequency[0][0] |
|
207 | 209 | |
|
208 | 210 | |
|
209 | 211 | return 1 |
|
210 | 212 | |
|
211 | 213 | |
|
212 | 214 | def createBuffers(self): |
|
213 | 215 | |
|
214 | 216 | pass |
|
215 | 217 | |
|
216 | 218 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): |
|
217 | 219 | self.path = path |
|
218 | 220 | self.startDate = startDate |
|
219 | 221 | self.endDate = endDate |
|
220 | 222 | self.startTime = startTime |
|
221 | 223 | self.endTime = endTime |
|
222 | 224 | self.walk = walk |
|
223 | 225 | |
|
224 | 226 | def __checkPath(self): |
|
225 | 227 | if os.path.exists(self.path): |
|
226 | 228 | self.status = 1 |
|
227 | 229 | else: |
|
228 | 230 | self.status = 0 |
|
229 | 231 | print('Path:%s does not exists'%self.path) |
|
230 | 232 | |
|
231 | 233 | return |
|
232 | 234 | |
|
233 | 235 | |
|
234 | 236 | def __selDates(self, amisr_dirname_format): |
|
235 | 237 | try: |
|
236 | 238 | year = int(amisr_dirname_format[0:4]) |
|
237 | 239 | month = int(amisr_dirname_format[4:6]) |
|
238 | 240 | dom = int(amisr_dirname_format[6:8]) |
|
239 | 241 | thisDate = datetime.date(year,month,dom) |
|
240 | 242 | |
|
241 | 243 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
242 | 244 | return amisr_dirname_format |
|
243 | 245 | except: |
|
244 | 246 | return None |
|
245 | 247 | |
|
246 | 248 | |
|
247 | 249 | def __findDataForDates(self,online=False): |
|
248 | 250 | |
|
249 | 251 | if not(self.status): |
|
250 | 252 | return None |
|
251 | 253 | |
|
252 | 254 | pat = '\d+.\d+' |
|
253 | 255 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] |
|
254 | 256 | dirnameList = [x for x in dirnameList if x!=None] |
|
255 | 257 | dirnameList = [x.string for x in dirnameList] |
|
256 | 258 | if not(online): |
|
257 | 259 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
258 | 260 | dirnameList = [x for x in dirnameList if x!=None] |
|
259 | 261 | if len(dirnameList)>0: |
|
260 | 262 | self.status = 1 |
|
261 | 263 | self.dirnameList = dirnameList |
|
262 | 264 | self.dirnameList.sort() |
|
263 | 265 | else: |
|
264 | 266 | self.status = 0 |
|
265 | 267 | return None |
|
266 | 268 | |
|
267 | 269 | def __getTimeFromData(self): |
|
268 | 270 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) |
|
269 | 271 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) |
|
270 | 272 | |
|
271 | 273 | print('Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader)) |
|
272 | 274 | print('........................................') |
|
273 | 275 | filter_filenameList = [] |
|
274 | 276 | self.filenameList.sort() |
|
275 | 277 | #for i in range(len(self.filenameList)-1): |
|
276 | 278 | for i in range(len(self.filenameList)): |
|
277 | 279 | filename = self.filenameList[i] |
|
278 | 280 | fp = h5py.File(filename,'r') |
|
279 | 281 | time_str = fp.get('Time/RadacTimeString') |
|
280 | 282 | |
|
281 | 283 | startDateTimeStr_File = time_str[0][0].decode('UTF-8').split('.')[0] |
|
282 | 284 | #startDateTimeStr_File = "2019-12-16 09:21:11" |
|
283 | 285 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
284 | 286 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
285 | 287 | |
|
286 | 288 | #endDateTimeStr_File = "2019-12-16 11:10:11" |
|
287 | 289 | endDateTimeStr_File = time_str[-1][-1].decode('UTF-8').split('.')[0] |
|
288 | 290 | junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
289 | 291 | endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
290 | 292 | |
|
291 | 293 | fp.close() |
|
292 | 294 | |
|
293 | 295 | #print("check time", startDateTime_File) |
|
294 | 296 | if self.timezone == 'lt': |
|
295 | 297 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) |
|
296 | 298 | endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300) |
|
297 | 299 | if (endDateTime_File>=startDateTime_Reader and endDateTime_File<=endDateTime_Reader): |
|
298 | 300 | filter_filenameList.append(filename) |
|
299 | 301 | |
|
300 | 302 | if (endDateTime_File>endDateTime_Reader): |
|
301 | 303 | break |
|
302 | 304 | |
|
303 | 305 | |
|
304 | 306 | filter_filenameList.sort() |
|
305 | 307 | self.filenameList = filter_filenameList |
|
306 | 308 | return 1 |
|
307 | 309 | |
|
308 | 310 | def __filterByGlob1(self, dirName): |
|
309 | 311 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) |
|
310 | 312 | filter_files.sort() |
|
311 | 313 | filterDict = {} |
|
312 | 314 | filterDict.setdefault(dirName) |
|
313 | 315 | filterDict[dirName] = filter_files |
|
314 | 316 | return filterDict |
|
315 | 317 | |
|
316 | 318 | def __getFilenameList(self, fileListInKeys, dirList): |
|
317 | 319 | for value in fileListInKeys: |
|
318 | 320 | dirName = list(value.keys())[0] |
|
319 | 321 | for file in value[dirName]: |
|
320 | 322 | filename = os.path.join(dirName, file) |
|
321 | 323 | self.filenameList.append(filename) |
|
322 | 324 | |
|
323 | 325 | |
|
324 | 326 | def __selectDataForTimes(self, online=False): |
|
325 | 327 | #aun no esta implementado el filtro for tiempo |
|
326 | 328 | if not(self.status): |
|
327 | 329 | return None |
|
328 | 330 | |
|
329 | 331 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
330 | 332 | |
|
331 | 333 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] |
|
332 | 334 | |
|
333 | 335 | self.__getFilenameList(fileListInKeys, dirList) |
|
334 | 336 | if not(online): |
|
335 | 337 | #filtro por tiempo |
|
336 | 338 | if not(self.all): |
|
337 | 339 | self.__getTimeFromData() |
|
338 | 340 | |
|
339 | 341 | if len(self.filenameList)>0: |
|
340 | 342 | self.status = 1 |
|
341 | 343 | self.filenameList.sort() |
|
342 | 344 | else: |
|
343 | 345 | self.status = 0 |
|
344 | 346 | return None |
|
345 | 347 | |
|
346 | 348 | else: |
|
347 | 349 | #get the last file - 1 |
|
348 | 350 | self.filenameList = [self.filenameList[-1]] |
|
349 | 351 | new_dirnameList = [] |
|
350 | 352 | for dirname in self.dirnameList: |
|
351 | 353 | junk = numpy.array([dirname in x for x in self.filenameList]) |
|
352 | 354 | junk_sum = junk.sum() |
|
353 | 355 | if junk_sum > 0: |
|
354 | 356 | new_dirnameList.append(dirname) |
|
355 | 357 | self.dirnameList = new_dirnameList |
|
356 | 358 | return 1 |
|
357 | 359 | |
|
358 | 360 | def searchFilesOnLine(self, path, startDate, endDate, startTime=datetime.time(0,0,0), |
|
359 | 361 | endTime=datetime.time(23,59,59),walk=True): |
|
360 | 362 | |
|
361 | 363 | if endDate ==None: |
|
362 | 364 | startDate = datetime.datetime.utcnow().date() |
|
363 | 365 | endDate = datetime.datetime.utcnow().date() |
|
364 | 366 | |
|
365 | 367 | self.__setParameters(path=path, startDate=startDate, endDate=endDate,startTime = startTime,endTime=endTime, walk=walk) |
|
366 | 368 | |
|
367 | 369 | self.__checkPath() |
|
368 | 370 | |
|
369 | 371 | self.__findDataForDates(online=True) |
|
370 | 372 | |
|
371 | 373 | self.dirnameList = [self.dirnameList[-1]] |
|
372 | 374 | |
|
373 | 375 | self.__selectDataForTimes(online=True) |
|
374 | 376 | |
|
375 | 377 | return |
|
376 | 378 | |
|
377 | 379 | |
|
378 | 380 | def searchFilesOffLine(self, |
|
379 | 381 | path, |
|
380 | 382 | startDate, |
|
381 | 383 | endDate, |
|
382 | 384 | startTime=datetime.time(0,0,0), |
|
383 | 385 | endTime=datetime.time(23,59,59), |
|
384 | 386 | walk=True): |
|
385 | 387 | |
|
386 | 388 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
387 | 389 | |
|
388 | 390 | self.__checkPath() |
|
389 | 391 | |
|
390 | 392 | self.__findDataForDates() |
|
391 | 393 | |
|
392 | 394 | self.__selectDataForTimes() |
|
393 | 395 | |
|
394 | 396 | for i in range(len(self.filenameList)): |
|
395 | 397 | print("%s" %(self.filenameList[i])) |
|
396 | 398 | |
|
397 | 399 | return |
|
398 | 400 | |
|
399 | 401 | def __setNextFileOffline(self): |
|
400 | 402 | |
|
401 | 403 | try: |
|
402 | 404 | self.filename = self.filenameList[self.fileIndex] |
|
403 | 405 | self.amisrFilePointer = h5py.File(self.filename,'r') |
|
404 | 406 | self.fileIndex += 1 |
|
405 | 407 | except: |
|
406 | 408 | self.flagNoMoreFiles = 1 |
|
407 | 409 | print("No more Files") |
|
408 | 410 | return 0 |
|
409 | 411 | |
|
410 | 412 | self.flagIsNewFile = 1 |
|
411 | 413 | print("Setting the file: %s"%self.filename) |
|
412 | 414 | |
|
413 | 415 | return 1 |
|
414 | 416 | |
|
415 | 417 | |
|
416 | 418 | def __setNextFileOnline(self): |
|
417 | 419 | filename = self.filenameList[0] |
|
418 | 420 | if self.__filename_online != None: |
|
419 | 421 | self.__selectDataForTimes(online=True) |
|
420 | 422 | filename = self.filenameList[0] |
|
421 | 423 | wait = 0 |
|
422 | self.__waitForNewFile=180 ## DEBUG: | |
|
424 | #self.__waitForNewFile=180 ## DEBUG: | |
|
423 | 425 | while self.__filename_online == filename: |
|
424 | 426 | print('waiting %d seconds to get a new file...'%(self.__waitForNewFile)) |
|
425 | 427 | if wait == 5: |
|
426 | 428 | self.flagNoMoreFiles = 1 |
|
427 | 429 | return 0 |
|
428 | 430 | sleep(self.__waitForNewFile) |
|
429 | 431 | self.__selectDataForTimes(online=True) |
|
430 | 432 | filename = self.filenameList[0] |
|
431 | 433 | wait += 1 |
|
432 | 434 | |
|
433 | 435 | self.__filename_online = filename |
|
434 | 436 | |
|
435 | 437 | self.amisrFilePointer = h5py.File(filename,'r') |
|
436 | 438 | self.flagIsNewFile = 1 |
|
437 | 439 | self.filename = filename |
|
438 | 440 | print("Setting the file: %s"%self.filename) |
|
439 | 441 | return 1 |
|
440 | 442 | |
|
441 | 443 | |
|
442 | 444 | def readData(self): |
|
443 | 445 | buffer = self.amisrFilePointer.get('Raw11/Data/Samples/Data') |
|
444 | 446 | re = buffer[:,:,:,0] |
|
445 | 447 | im = buffer[:,:,:,1] |
|
446 | 448 | dataset = re + im*1j |
|
447 | 449 | |
|
448 | 450 | self.radacTime = self.amisrFilePointer.get('Raw11/Data/RadacHeader/RadacTime') |
|
449 | 451 | timeset = self.radacTime[:,0] |
|
450 | 452 | |
|
451 | 453 | return dataset,timeset |
|
452 | 454 | |
|
453 | 455 | def reshapeData(self): |
|
454 | 456 | #self.beamCodeByPulse, self.beamCode, self.nblocks, self.nprofiles, self.nsa, |
|
455 | 457 | channels = self.beamCodeByPulse[0,:] |
|
456 | 458 | nchan = self.nchannels |
|
457 | 459 | #self.newProfiles = self.nprofiles/nchan #must be defined on filljroheader |
|
458 | 460 | nblocks = self.nblocks |
|
459 | 461 | nsamples = self.nsa |
|
460 | 462 | |
|
461 | 463 | #Dimensions : nChannels, nProfiles, nSamples |
|
462 | 464 | new_block = numpy.empty((nblocks, nchan, numpy.int_(self.newProfiles), nsamples), dtype="complex64") |
|
463 | 465 | ############################################ |
|
464 | 466 | |
|
465 | 467 | for thisChannel in range(nchan): |
|
466 | 468 | new_block[:,thisChannel,:,:] = self.dataset[:,numpy.where(channels==self.beamCode[thisChannel])[0],:] |
|
467 | 469 | |
|
468 | 470 | |
|
469 | 471 | new_block = numpy.transpose(new_block, (1,0,2,3)) |
|
470 | 472 | new_block = numpy.reshape(new_block, (nchan,-1, nsamples)) |
|
471 | 473 | |
|
472 | 474 | return new_block |
|
473 | 475 | |
|
474 | 476 | def updateIndexes(self): |
|
475 | 477 | |
|
476 | 478 | pass |
|
477 | 479 | |
|
478 | 480 | def fillJROHeader(self): |
|
479 | 481 | |
|
480 | 482 | #fill radar controller header |
|
481 | 483 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ipp=self.__ippKm, |
|
482 | 484 | txA=self.__txA, |
|
483 | 485 | txB=0, |
|
484 | 486 | nWindows=1, |
|
485 | 487 | nHeights=self.__nSamples, |
|
486 | 488 | firstHeight=self.__firstHeight, |
|
487 | 489 | deltaHeight=self.__deltaHeight, |
|
488 | 490 | codeType=self.__codeType, |
|
489 | 491 | nCode=self.__nCode, nBaud=self.__nBaud, |
|
490 | 492 | code = self.__code, |
|
491 | 493 | fClock=1) |
|
492 | 494 | |
|
493 | 495 | #fill system header |
|
494 | 496 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, |
|
495 | 497 | nProfiles=self.newProfiles, |
|
496 | 498 | nChannels=len(self.__channelList), |
|
497 | 499 | adcResolution=14, |
|
498 | 500 | pciDioBusWidth=32) |
|
499 | 501 | |
|
500 | 502 | self.dataOut.type = "Voltage" |
|
501 | 503 | |
|
502 | 504 | self.dataOut.data = None |
|
503 | 505 | |
|
504 | 506 | self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
505 | 507 | |
|
506 | 508 | # self.dataOut.nChannels = 0 |
|
507 | 509 | |
|
508 | 510 | # self.dataOut.nHeights = 0 |
|
509 | 511 | |
|
510 | 512 | self.dataOut.nProfiles = self.newProfiles*self.nblocks |
|
511 | 513 | |
|
512 | 514 | #self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth |
|
513 | 515 | ranges = numpy.reshape(self.rangeFromFile.value,(-1)) |
|
514 | 516 | self.dataOut.heightList = ranges/1000.0 #km |
|
515 | 517 | |
|
516 | 518 | |
|
517 | 519 | self.dataOut.channelList = self.__channelList |
|
518 | 520 | |
|
519 | 521 | self.dataOut.blocksize = self.dataOut.nChannels * self.dataOut.nHeights |
|
520 | 522 | |
|
521 | 523 | # self.dataOut.channelIndexList = None |
|
522 | 524 | |
|
523 | 525 | self.dataOut.flagNoData = True |
|
524 | 526 | |
|
525 | 527 | #Set to TRUE if the data is discontinuous |
|
526 | 528 | self.dataOut.flagDiscontinuousBlock = False |
|
527 | 529 | |
|
528 | 530 | self.dataOut.utctime = None |
|
529 | 531 | |
|
530 | 532 | #self.dataOut.timeZone = -5 #self.__timezone/60 #timezone like jroheader, difference in minutes between UTC and localtime |
|
531 | 533 | if self.timezone == 'lt': |
|
532 | 534 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes |
|
533 | 535 | else: |
|
534 | 536 | self.dataOut.timeZone = 0 #by default time is UTC |
|
535 | 537 | |
|
536 | 538 | self.dataOut.dstFlag = 0 |
|
537 | 539 | |
|
538 | 540 | self.dataOut.errorCount = 0 |
|
539 | 541 | |
|
540 | 542 | self.dataOut.nCohInt = 1 |
|
541 | 543 | |
|
542 | 544 | self.dataOut.flagDecodeData = False #asumo que la data esta decodificada |
|
543 | 545 | |
|
544 | 546 | self.dataOut.flagDeflipData = False #asumo que la data esta sin flip |
|
545 | 547 | |
|
546 | 548 | self.dataOut.flagShiftFFT = False |
|
547 | 549 | |
|
548 | 550 | self.dataOut.ippSeconds = self.ippSeconds |
|
549 | 551 | |
|
550 | 552 | #Time interval between profiles |
|
551 | 553 | #self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
552 | 554 | |
|
553 | 555 | self.dataOut.frequency = self.__frequency |
|
554 | 556 | self.dataOut.realtime = self.online |
|
555 | 557 | pass |
|
556 | 558 | |
|
557 | 559 | def readNextFile(self,online=False): |
|
558 | 560 | |
|
559 | 561 | if not(online): |
|
560 | 562 | newFile = self.__setNextFileOffline() |
|
561 | 563 | else: |
|
562 | 564 | newFile = self.__setNextFileOnline() |
|
563 | 565 | |
|
564 | 566 | if not(newFile): |
|
565 | 567 | self.dataOut.error = True |
|
566 | 568 | return 0 |
|
567 | 569 | |
|
568 | 570 | if not self.readAMISRHeader(self.amisrFilePointer): |
|
569 | 571 | self.dataOut.error = True |
|
570 | 572 | return 0 |
|
571 | 573 | |
|
572 | 574 | self.createBuffers() |
|
573 | 575 | self.fillJROHeader() |
|
574 | 576 | |
|
575 | 577 | #self.__firstFile = False |
|
576 | 578 | |
|
577 | 579 | |
|
578 | 580 | |
|
579 | 581 | self.dataset,self.timeset = self.readData() |
|
580 | 582 | |
|
581 | 583 | if self.endDate!=None: |
|
582 | 584 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) |
|
583 | 585 | time_str = self.amisrFilePointer.get('Time/RadacTimeString') |
|
584 | 586 | startDateTimeStr_File = time_str[0][0].decode('UTF-8').split('.')[0] |
|
585 | 587 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
586 | 588 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
587 | 589 | if self.timezone == 'lt': |
|
588 | 590 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) |
|
589 | 591 | if (startDateTime_File>endDateTime_Reader): |
|
590 | 592 | return 0 |
|
591 | 593 | |
|
592 | 594 | self.jrodataset = self.reshapeData() |
|
593 | 595 | #----self.updateIndexes() |
|
594 | 596 | self.profileIndex = 0 |
|
595 | 597 | |
|
596 | 598 | return 1 |
|
597 | 599 | |
|
598 | 600 | |
|
599 | 601 | def __hasNotDataInBuffer(self): |
|
600 | 602 | if self.profileIndex >= (self.newProfiles*self.nblocks): |
|
601 | 603 | return 1 |
|
602 | 604 | return 0 |
|
603 | 605 | |
|
604 | 606 | |
|
605 | 607 | def getData(self): |
|
606 | 608 | |
|
607 | 609 | if self.flagNoMoreFiles: |
|
608 | 610 | self.dataOut.flagNoData = True |
|
609 | 611 | return 0 |
|
610 | 612 | |
|
611 | 613 | if self.__hasNotDataInBuffer(): |
|
612 | 614 | if not (self.readNextFile(self.online)): |
|
613 | 615 | return 0 |
|
614 | 616 | |
|
615 | 617 | |
|
616 | 618 | if self.dataset is None: # setear esta condicion cuando no hayan datos por leer |
|
617 | 619 | self.dataOut.flagNoData = True |
|
618 | 620 | return 0 |
|
619 | 621 | |
|
620 | 622 | #self.dataOut.data = numpy.reshape(self.jrodataset[self.profileIndex,:],(1,-1)) |
|
621 | 623 | |
|
622 | 624 | self.dataOut.data = self.jrodataset[:,self.profileIndex,:] |
|
623 | 625 | |
|
624 | 626 | #print("R_t",self.timeset) |
|
625 | 627 | |
|
626 | 628 | #self.dataOut.utctime = self.jrotimeset[self.profileIndex] |
|
627 | 629 | #verificar basic header de jro data y ver si es compatible con este valor |
|
628 | 630 | #self.dataOut.utctime = self.timeset + (self.profileIndex * self.ippSeconds * self.nchannels) |
|
629 | 631 | indexprof = numpy.mod(self.profileIndex, self.newProfiles) |
|
630 | 632 | indexblock = self.profileIndex/self.newProfiles |
|
631 | 633 | #print (indexblock, indexprof) |
|
632 | 634 | diffUTC = 1.8e4 #UTC diference from peru in seconds --Joab |
|
633 | 635 | diffUTC = 0 |
|
634 | 636 | t_comp = (indexprof * self.ippSeconds * self.nchannels) + diffUTC # |
|
635 | 637 | |
|
636 | 638 | #print("utc :",indexblock," __ ",t_comp) |
|
637 | 639 | #print(numpy.shape(self.timeset)) |
|
638 | 640 | self.dataOut.utctime = self.timeset[numpy.int_(indexblock)] + t_comp |
|
639 | 641 | #self.dataOut.utctime = self.timeset[self.profileIndex] + t_comp |
|
640 | 642 | #print(self.dataOut.utctime) |
|
641 | 643 | self.dataOut.profileIndex = self.profileIndex |
|
642 | 644 | self.dataOut.flagNoData = False |
|
643 | 645 | # if indexprof == 0: |
|
644 | 646 | # print self.dataOut.utctime |
|
645 | 647 | |
|
646 | 648 | self.profileIndex += 1 |
|
647 | 649 | |
|
648 | 650 | return self.dataOut.data |
|
649 | 651 | |
|
650 | 652 | |
|
651 | 653 | def run(self, **kwargs): |
|
652 | 654 | ''' |
|
653 | 655 | This method will be called many times so here you should put all your code |
|
654 | 656 | ''' |
|
655 | 657 | #print("running kamisr") |
|
656 | 658 | if not self.isConfig: |
|
657 | 659 | self.setup(**kwargs) |
|
658 | 660 | self.isConfig = True |
|
659 | 661 | |
|
660 | 662 | self.getData() |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
This diff has been collapsed as it changes many lines, (1558 lines changed) Show them Hide them |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed, binary diff hidden |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now