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