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