@@ -1,1035 +1,1037 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time |
|
2 | import time | |
3 | import os |
|
3 | import os | |
4 | import h5py |
|
4 | import h5py | |
5 | import re |
|
5 | import re | |
6 | import datetime |
|
6 | import datetime | |
7 |
|
7 | |||
8 | from schainpy.model.data.jrodata import * |
|
8 | from schainpy.model.data.jrodata import * | |
9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
10 | # from .jroIO_base import * |
|
10 | # from .jroIO_base import * | |
11 | from schainpy.model.io.jroIO_base import * |
|
11 | from schainpy.model.io.jroIO_base import * | |
12 | import schainpy |
|
12 | import schainpy | |
13 | from schainpy.utils import log |
|
13 | from schainpy.utils import log | |
14 |
|
14 | |||
15 | @MPDecorator |
|
15 | @MPDecorator | |
16 | class ParamReader(JRODataReader,ProcessingUnit): |
|
16 | class ParamReader(JRODataReader,ProcessingUnit): | |
17 | ''' |
|
17 | ''' | |
18 | Reads HDF5 format files |
|
18 | Reads HDF5 format files | |
19 |
|
19 | |||
20 | path |
|
20 | path | |
21 |
|
21 | |||
22 | startDate |
|
22 | startDate | |
23 |
|
23 | |||
24 | endDate |
|
24 | endDate | |
25 |
|
25 | |||
26 | startTime |
|
26 | startTime | |
27 |
|
27 | |||
28 | endTime |
|
28 | endTime | |
29 | ''' |
|
29 | ''' | |
30 |
|
30 | |||
31 | ext = ".hdf5" |
|
31 | ext = ".hdf5" | |
32 |
|
32 | |||
33 | optchar = "D" |
|
33 | optchar = "D" | |
34 |
|
34 | |||
35 | timezone = None |
|
35 | timezone = None | |
36 |
|
36 | |||
37 | startTime = None |
|
37 | startTime = None | |
38 |
|
38 | |||
39 | endTime = None |
|
39 | endTime = None | |
40 |
|
40 | |||
41 | fileIndex = None |
|
41 | fileIndex = None | |
42 |
|
42 | |||
43 | utcList = None #To select data in the utctime list |
|
43 | utcList = None #To select data in the utctime list | |
44 |
|
44 | |||
45 | blockList = None #List to blocks to be read from the file |
|
45 | blockList = None #List to blocks to be read from the file | |
46 |
|
46 | |||
47 | blocksPerFile = None #Number of blocks to be read |
|
47 | blocksPerFile = None #Number of blocks to be read | |
48 |
|
48 | |||
49 | blockIndex = None |
|
49 | blockIndex = None | |
50 |
|
50 | |||
51 | path = None |
|
51 | path = None | |
52 |
|
52 | |||
53 | #List of Files |
|
53 | #List of Files | |
54 |
|
54 | |||
55 | filenameList = None |
|
55 | filenameList = None | |
56 |
|
56 | |||
57 | datetimeList = None |
|
57 | datetimeList = None | |
58 |
|
58 | |||
59 | #Hdf5 File |
|
59 | #Hdf5 File | |
60 |
|
60 | |||
61 | listMetaname = None |
|
61 | listMetaname = None | |
62 |
|
62 | |||
63 | listMeta = None |
|
63 | listMeta = None | |
64 |
|
64 | |||
65 | listDataname = None |
|
65 | listDataname = None | |
66 |
|
66 | |||
67 | listData = None |
|
67 | listData = None | |
68 |
|
68 | |||
69 | listShapes = None |
|
69 | listShapes = None | |
70 |
|
70 | |||
71 | fp = None |
|
71 | fp = None | |
72 |
|
72 | |||
73 | #dataOut reconstruction |
|
73 | #dataOut reconstruction | |
74 |
|
74 | |||
75 | dataOut = None |
|
75 | dataOut = None | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | def __init__(self):#, **kwargs): |
|
78 | def __init__(self):#, **kwargs): | |
79 | ProcessingUnit.__init__(self) #, **kwargs) |
|
79 | ProcessingUnit.__init__(self) #, **kwargs) | |
80 | self.dataOut = Parameters() |
|
80 | self.dataOut = Parameters() | |
81 | return |
|
81 | return | |
82 |
|
82 | |||
83 | def setup(self, **kwargs): |
|
83 | def setup(self, **kwargs): | |
84 |
|
84 | |||
85 | path = kwargs['path'] |
|
85 | path = kwargs['path'] | |
86 | startDate = kwargs['startDate'] |
|
86 | startDate = kwargs['startDate'] | |
87 | endDate = kwargs['endDate'] |
|
87 | endDate = kwargs['endDate'] | |
88 | startTime = kwargs['startTime'] |
|
88 | startTime = kwargs['startTime'] | |
89 | endTime = kwargs['endTime'] |
|
89 | endTime = kwargs['endTime'] | |
90 | walk = kwargs['walk'] |
|
90 | walk = kwargs['walk'] | |
91 | if 'ext' in kwargs: |
|
91 | if 'ext' in kwargs: | |
92 | ext = kwargs['ext'] |
|
92 | ext = kwargs['ext'] | |
93 | else: |
|
93 | else: | |
94 | ext = '.hdf5' |
|
94 | ext = '.hdf5' | |
95 | if 'timezone' in kwargs: |
|
95 | if 'timezone' in kwargs: | |
96 | self.timezone = kwargs['timezone'] |
|
96 | self.timezone = kwargs['timezone'] | |
97 | else: |
|
97 | else: | |
98 | self.timezone = 'lt' |
|
98 | self.timezone = 'lt' | |
99 |
|
99 | |||
100 | print("[Reading] Searching files in offline mode ...") |
|
100 | print("[Reading] Searching files in offline mode ...") | |
101 | pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
101 | pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
102 | startTime=startTime, endTime=endTime, |
|
102 | startTime=startTime, endTime=endTime, | |
103 | ext=ext, walk=walk) |
|
103 | ext=ext, walk=walk) | |
104 |
|
104 | |||
105 | if not(filenameList): |
|
105 | if not(filenameList): | |
106 | print("There is no files into the folder: %s"%(path)) |
|
106 | print("There is no files into the folder: %s"%(path)) | |
107 | sys.exit(-1) |
|
107 | sys.exit(-1) | |
108 |
|
108 | |||
109 | self.fileIndex = -1 |
|
109 | self.fileIndex = -1 | |
110 | self.startTime = startTime |
|
110 | self.startTime = startTime | |
111 | self.endTime = endTime |
|
111 | self.endTime = endTime | |
112 |
|
112 | |||
113 | self.__readMetadata() |
|
113 | self.__readMetadata() | |
114 |
|
114 | |||
115 | self.__setNextFileOffline() |
|
115 | self.__setNextFileOffline() | |
116 |
|
116 | |||
117 | return |
|
117 | return | |
118 |
|
118 | |||
119 | def searchFilesOffLine(self, |
|
119 | def searchFilesOffLine(self, | |
120 | path, |
|
120 | path, | |
121 | startDate=None, |
|
121 | startDate=None, | |
122 | endDate=None, |
|
122 | endDate=None, | |
123 | startTime=datetime.time(0,0,0), |
|
123 | startTime=datetime.time(0,0,0), | |
124 | endTime=datetime.time(23,59,59), |
|
124 | endTime=datetime.time(23,59,59), | |
125 | ext='.hdf5', |
|
125 | ext='.hdf5', | |
126 | walk=True): |
|
126 | walk=True): | |
127 |
|
127 | |||
128 | expLabel = '' |
|
128 | expLabel = '' | |
129 | self.filenameList = [] |
|
129 | self.filenameList = [] | |
130 | self.datetimeList = [] |
|
130 | self.datetimeList = [] | |
131 |
|
131 | |||
132 | pathList = [] |
|
132 | pathList = [] | |
133 |
|
133 | |||
134 | JRODataObj = JRODataReader() |
|
134 | JRODataObj = JRODataReader() | |
135 | dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True) |
|
135 | dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True) | |
136 |
|
136 | |||
137 | if dateList == []: |
|
137 | if dateList == []: | |
138 | print("[Reading] No *%s files in %s from %s to %s)"%(ext, path, |
|
138 | print("[Reading] No *%s files in %s from %s to %s)"%(ext, path, | |
139 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
139 | datetime.datetime.combine(startDate,startTime).ctime(), | |
140 | datetime.datetime.combine(endDate,endTime).ctime())) |
|
140 | datetime.datetime.combine(endDate,endTime).ctime())) | |
141 |
|
141 | |||
142 | return None, None |
|
142 | return None, None | |
143 |
|
143 | |||
144 | if len(dateList) > 1: |
|
144 | if len(dateList) > 1: | |
145 | print("[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)) |
|
145 | print("[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)) | |
146 | else: |
|
146 | else: | |
147 | print("[Reading] data was found for the date %s" %(dateList[0])) |
|
147 | print("[Reading] data was found for the date %s" %(dateList[0])) | |
148 |
|
148 | |||
149 | filenameList = [] |
|
149 | filenameList = [] | |
150 | datetimeList = [] |
|
150 | datetimeList = [] | |
151 |
|
151 | |||
152 | #---------------------------------------------------------------------------------- |
|
152 | #---------------------------------------------------------------------------------- | |
153 |
|
153 | |||
154 | for thisPath in pathList: |
|
154 | for thisPath in pathList: | |
155 | # thisPath = pathList[pathDict[file]] |
|
155 | # thisPath = pathList[pathDict[file]] | |
156 |
|
156 | |||
157 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
157 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
158 | fileList.sort() |
|
158 | fileList.sort() | |
159 |
|
159 | |||
160 | for file in fileList: |
|
160 | for file in fileList: | |
161 |
|
161 | |||
162 | filename = os.path.join(thisPath,file) |
|
162 | filename = os.path.join(thisPath,file) | |
163 |
|
163 | |||
164 | if not isFileInDateRange(filename, startDate, endDate): |
|
164 | if not isFileInDateRange(filename, startDate, endDate): | |
165 | continue |
|
165 | continue | |
166 |
|
166 | |||
167 | thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime) |
|
167 | thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime) | |
168 |
|
168 | |||
169 | if not(thisDatetime): |
|
169 | if not(thisDatetime): | |
170 | continue |
|
170 | continue | |
171 |
|
171 | |||
172 | filenameList.append(filename) |
|
172 | filenameList.append(filename) | |
173 | datetimeList.append(thisDatetime) |
|
173 | datetimeList.append(thisDatetime) | |
174 |
|
174 | |||
175 | if not(filenameList): |
|
175 | if not(filenameList): | |
176 | print("[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())) |
|
176 | print("[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())) | |
177 | return None, None |
|
177 | return None, None | |
178 |
|
178 | |||
179 | print("[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)) |
|
179 | print("[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)) | |
180 | print() |
|
180 | print() | |
181 |
|
181 | |||
182 | self.filenameList = filenameList |
|
182 | self.filenameList = filenameList | |
183 | self.datetimeList = datetimeList |
|
183 | self.datetimeList = datetimeList | |
184 |
|
184 | |||
185 | return pathList, filenameList |
|
185 | return pathList, filenameList | |
186 |
|
186 | |||
187 | def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime): |
|
187 | def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime): | |
188 |
|
188 | |||
189 | """ |
|
189 | """ | |
190 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
190 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
191 |
|
191 | |||
192 | Inputs: |
|
192 | Inputs: | |
193 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
193 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
194 |
|
194 | |||
195 | startDate : fecha inicial del rango seleccionado en formato datetime.date |
|
195 | startDate : fecha inicial del rango seleccionado en formato datetime.date | |
196 |
|
196 | |||
197 | endDate : fecha final del rango seleccionado en formato datetime.date |
|
197 | endDate : fecha final del rango seleccionado en formato datetime.date | |
198 |
|
198 | |||
199 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
199 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
200 |
|
200 | |||
201 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
201 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
202 |
|
202 | |||
203 | Return: |
|
203 | Return: | |
204 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
204 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
205 | fecha especificado, de lo contrario retorna False. |
|
205 | fecha especificado, de lo contrario retorna False. | |
206 |
|
206 | |||
207 | Excepciones: |
|
207 | Excepciones: | |
208 | Si el archivo no existe o no puede ser abierto |
|
208 | Si el archivo no existe o no puede ser abierto | |
209 | Si la cabecera no puede ser leida. |
|
209 | Si la cabecera no puede ser leida. | |
210 |
|
210 | |||
211 | """ |
|
211 | """ | |
212 |
|
212 | |||
213 | try: |
|
213 | try: | |
214 | fp = h5py.File(filename,'r') |
|
214 | fp = h5py.File(filename,'r') | |
215 | grp1 = fp['Data'] |
|
215 | grp1 = fp['Data'] | |
216 |
|
216 | |||
217 | except IOError: |
|
217 | except IOError: | |
218 | traceback.print_exc() |
|
218 | traceback.print_exc() | |
219 | raise IOError("The file %s can't be opened" %(filename)) |
|
219 | raise IOError("The file %s can't be opened" %(filename)) | |
220 | #chino rata |
|
220 | #chino rata | |
221 | #In case has utctime attribute |
|
221 | #In case has utctime attribute | |
222 | grp2 = grp1['utctime'] |
|
222 | grp2 = grp1['utctime'] | |
223 | # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time |
|
223 | # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time | |
224 | thisUtcTime = grp2.value[0] |
|
224 | thisUtcTime = grp2.value[0] | |
225 |
|
225 | |||
226 | fp.close() |
|
226 | fp.close() | |
227 |
|
227 | |||
228 | if self.timezone == 'lt': |
|
228 | if self.timezone == 'lt': | |
229 | thisUtcTime -= 5*3600 |
|
229 | thisUtcTime -= 5*3600 | |
230 |
|
230 | |||
231 | thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600) |
|
231 | thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600) | |
232 | # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0]) |
|
232 | # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0]) | |
233 | thisDate = thisDatetime.date() |
|
233 | thisDate = thisDatetime.date() | |
234 | thisTime = thisDatetime.time() |
|
234 | thisTime = thisDatetime.time() | |
235 |
|
235 | |||
236 | startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds() |
|
236 | startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds() | |
237 | endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds() |
|
237 | endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds() | |
238 |
|
238 | |||
239 | #General case |
|
239 | #General case | |
240 | # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o |
|
240 | # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o | |
241 | #-----------o----------------------------o----------- |
|
241 | #-----------o----------------------------o----------- | |
242 | # startTime endTime |
|
242 | # startTime endTime | |
243 |
|
243 | |||
244 | if endTime >= startTime: |
|
244 | if endTime >= startTime: | |
245 | thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime) |
|
245 | thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime) | |
246 | if numpy.any(thisUtcLog): #If there is one block between the hours mentioned |
|
246 | if numpy.any(thisUtcLog): #If there is one block between the hours mentioned | |
247 | return thisDatetime |
|
247 | return thisDatetime | |
248 | return None |
|
248 | return None | |
249 |
|
249 | |||
250 | #If endTime < startTime then endTime belongs to the next day |
|
250 | #If endTime < startTime then endTime belongs to the next day | |
251 | #<<<<<<<<<<<o o>>>>>>>>>>> |
|
251 | #<<<<<<<<<<<o o>>>>>>>>>>> | |
252 | #-----------o----------------------------o----------- |
|
252 | #-----------o----------------------------o----------- | |
253 | # endTime startTime |
|
253 | # endTime startTime | |
254 |
|
254 | |||
255 | if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime): |
|
255 | if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime): | |
256 | return None |
|
256 | return None | |
257 |
|
257 | |||
258 | if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime): |
|
258 | if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime): | |
259 | return None |
|
259 | return None | |
260 |
|
260 | |||
261 | if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime): |
|
261 | if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime): | |
262 | return None |
|
262 | return None | |
263 |
|
263 | |||
264 | return thisDatetime |
|
264 | return thisDatetime | |
265 |
|
265 | |||
266 | def __setNextFileOffline(self): |
|
266 | def __setNextFileOffline(self): | |
267 |
|
267 | |||
268 | self.fileIndex += 1 |
|
268 | self.fileIndex += 1 | |
269 | idFile = self.fileIndex |
|
269 | idFile = self.fileIndex | |
270 |
|
270 | |||
271 | if not(idFile < len(self.filenameList)): |
|
271 | if not(idFile < len(self.filenameList)): | |
272 | print("No more Files") |
|
272 | print("No more Files") | |
273 | return 0 |
|
273 | return 0 | |
274 |
|
274 | |||
275 | filename = self.filenameList[idFile] |
|
275 | filename = self.filenameList[idFile] | |
276 |
|
276 | |||
277 | filePointer = h5py.File(filename,'r') |
|
277 | filePointer = h5py.File(filename,'r') | |
278 |
|
278 | |||
279 | self.filename = filename |
|
279 | self.filename = filename | |
280 |
|
280 | |||
281 | self.fp = filePointer |
|
281 | self.fp = filePointer | |
282 |
|
282 | |||
283 | print("Setting the file: %s"%self.filename) |
|
283 | print("Setting the file: %s"%self.filename) | |
284 |
|
284 | |||
285 | # self.__readMetadata() |
|
285 | # self.__readMetadata() | |
286 | self.__setBlockList() |
|
286 | self.__setBlockList() | |
287 | self.__readData() |
|
287 | self.__readData() | |
288 | # self.nRecords = self.fp['Data'].attrs['blocksPerFile'] |
|
288 | # self.nRecords = self.fp['Data'].attrs['blocksPerFile'] | |
289 | # self.nRecords = self.fp['Data'].attrs['nRecords'] |
|
289 | # self.nRecords = self.fp['Data'].attrs['nRecords'] | |
290 | self.blockIndex = 0 |
|
290 | self.blockIndex = 0 | |
291 | return 1 |
|
291 | return 1 | |
292 |
|
292 | |||
293 | def __setBlockList(self): |
|
293 | def __setBlockList(self): | |
294 | ''' |
|
294 | ''' | |
295 | Selects the data within the times defined |
|
295 | Selects the data within the times defined | |
296 |
|
296 | |||
297 | self.fp |
|
297 | self.fp | |
298 | self.startTime |
|
298 | self.startTime | |
299 | self.endTime |
|
299 | self.endTime | |
300 |
|
300 | |||
301 | self.blockList |
|
301 | self.blockList | |
302 | self.blocksPerFile |
|
302 | self.blocksPerFile | |
303 |
|
303 | |||
304 | ''' |
|
304 | ''' | |
305 | fp = self.fp |
|
305 | fp = self.fp | |
306 | startTime = self.startTime |
|
306 | startTime = self.startTime | |
307 | endTime = self.endTime |
|
307 | endTime = self.endTime | |
308 |
|
308 | |||
309 | grp = fp['Data'] |
|
309 | grp = fp['Data'] | |
310 | thisUtcTime = grp['utctime'].value.astype(numpy.float)[0] |
|
310 | thisUtcTime = grp['utctime'].value.astype(numpy.float)[0] | |
311 |
|
311 | |||
312 | #ERROOOOR |
|
312 | #ERROOOOR | |
313 | if self.timezone == 'lt': |
|
313 | if self.timezone == 'lt': | |
314 | thisUtcTime -= 5*3600 |
|
314 | thisUtcTime -= 5*3600 | |
315 |
|
315 | |||
316 | thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600) |
|
316 | thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600) | |
317 |
|
317 | |||
318 | thisDate = thisDatetime.date() |
|
318 | thisDate = thisDatetime.date() | |
319 | thisTime = thisDatetime.time() |
|
319 | thisTime = thisDatetime.time() | |
320 |
|
320 | |||
321 | startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
321 | startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |
322 | endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
322 | endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |
323 |
|
323 | |||
324 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] |
|
324 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] | |
325 |
|
325 | |||
326 | self.blockList = ind |
|
326 | self.blockList = ind | |
327 | self.blocksPerFile = len(ind) |
|
327 | self.blocksPerFile = len(ind) | |
328 |
|
328 | |||
329 | return |
|
329 | return | |
330 |
|
330 | |||
331 | def __readMetadata(self): |
|
331 | def __readMetadata(self): | |
332 | ''' |
|
332 | ''' | |
333 | Reads Metadata |
|
333 | Reads Metadata | |
334 |
|
334 | |||
335 | self.pathMeta |
|
335 | self.pathMeta | |
336 |
|
336 | |||
337 | self.listShapes |
|
337 | self.listShapes | |
338 | self.listMetaname |
|
338 | self.listMetaname | |
339 | self.listMeta |
|
339 | self.listMeta | |
340 |
|
340 | |||
341 | ''' |
|
341 | ''' | |
342 |
|
342 | |||
343 | # grp = self.fp['Data'] |
|
343 | # grp = self.fp['Data'] | |
344 | # pathMeta = os.path.join(self.path, grp.attrs['metadata']) |
|
344 | # pathMeta = os.path.join(self.path, grp.attrs['metadata']) | |
345 | # |
|
345 | # | |
346 | # if pathMeta == self.pathMeta: |
|
346 | # if pathMeta == self.pathMeta: | |
347 | # return |
|
347 | # return | |
348 | # else: |
|
348 | # else: | |
349 | # self.pathMeta = pathMeta |
|
349 | # self.pathMeta = pathMeta | |
350 | # |
|
350 | # | |
351 | # filePointer = h5py.File(self.pathMeta,'r') |
|
351 | # filePointer = h5py.File(self.pathMeta,'r') | |
352 | # groupPointer = filePointer['Metadata'] |
|
352 | # groupPointer = filePointer['Metadata'] | |
353 |
|
353 | |||
354 | filename = self.filenameList[0] |
|
354 | filename = self.filenameList[0] | |
355 |
|
355 | |||
356 | fp = h5py.File(filename,'r') |
|
356 | fp = h5py.File(filename,'r') | |
357 |
|
357 | |||
358 | gp = fp['Metadata'] |
|
358 | gp = fp['Metadata'] | |
359 |
|
359 | |||
360 | listMetaname = [] |
|
360 | listMetaname = [] | |
361 | listMetadata = [] |
|
361 | listMetadata = [] | |
362 | for item in list(gp.items()): |
|
362 | for item in list(gp.items()): | |
363 | name = item[0] |
|
363 | name = item[0] | |
364 |
|
364 | |||
365 | if name=='array dimensions': |
|
365 | if name=='array dimensions': | |
366 | table = gp[name][:] |
|
366 | table = gp[name][:] | |
367 | listShapes = {} |
|
367 | listShapes = {} | |
368 | for shapes in table: |
|
368 | for shapes in table: | |
369 | listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]]) |
|
369 | listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]]) | |
370 | else: |
|
370 | else: | |
371 | data = gp[name].value |
|
371 | data = gp[name].value | |
372 | listMetaname.append(name) |
|
372 | listMetaname.append(name) | |
373 | listMetadata.append(data) |
|
373 | listMetadata.append(data) | |
374 |
|
374 | |||
375 | # if name=='type': |
|
375 | # if name=='type': | |
376 | # self.__initDataOut(data) |
|
376 | # self.__initDataOut(data) | |
377 |
|
377 | |||
378 | self.listShapes = listShapes |
|
378 | self.listShapes = listShapes | |
379 | self.listMetaname = listMetaname |
|
379 | self.listMetaname = listMetaname | |
380 | self.listMeta = listMetadata |
|
380 | self.listMeta = listMetadata | |
381 |
|
381 | |||
382 | fp.close() |
|
382 | fp.close() | |
383 | return |
|
383 | return | |
384 |
|
384 | |||
385 | def __readData(self): |
|
385 | def __readData(self): | |
386 | grp = self.fp['Data'] |
|
386 | grp = self.fp['Data'] | |
387 | listdataname = [] |
|
387 | listdataname = [] | |
388 | listdata = [] |
|
388 | listdata = [] | |
389 |
|
389 | |||
390 | for item in list(grp.items()): |
|
390 | for item in list(grp.items()): | |
391 | name = item[0] |
|
391 | name = item[0] | |
392 | listdataname.append(name) |
|
392 | listdataname.append(name) | |
393 |
|
393 | |||
394 | array = self.__setDataArray(grp[name],self.listShapes[name]) |
|
394 | array = self.__setDataArray(grp[name],self.listShapes[name]) | |
395 | listdata.append(array) |
|
395 | listdata.append(array) | |
396 |
|
396 | |||
397 | self.listDataname = listdataname |
|
397 | self.listDataname = listdataname | |
398 | self.listData = listdata |
|
398 | self.listData = listdata | |
399 | return |
|
399 | return | |
400 |
|
400 | |||
401 | def __setDataArray(self, dataset, shapes): |
|
401 | def __setDataArray(self, dataset, shapes): | |
402 |
|
402 | |||
403 | nDims = shapes[0] |
|
403 | nDims = shapes[0] | |
404 |
|
404 | |||
405 | nDim2 = shapes[1] #Dimension 0 |
|
405 | nDim2 = shapes[1] #Dimension 0 | |
406 |
|
406 | |||
407 | nDim1 = shapes[2] #Dimension 1, number of Points or Parameters |
|
407 | nDim1 = shapes[2] #Dimension 1, number of Points or Parameters | |
408 |
|
408 | |||
409 | nDim0 = shapes[3] #Dimension 2, number of samples or ranges |
|
409 | nDim0 = shapes[3] #Dimension 2, number of samples or ranges | |
410 |
|
410 | |||
411 | mode = shapes[4] #Mode of storing |
|
411 | mode = shapes[4] #Mode of storing | |
412 |
|
412 | |||
413 | blockList = self.blockList |
|
413 | blockList = self.blockList | |
414 |
|
414 | |||
415 | blocksPerFile = self.blocksPerFile |
|
415 | blocksPerFile = self.blocksPerFile | |
416 |
|
416 | |||
417 | #Depending on what mode the data was stored |
|
417 | #Depending on what mode the data was stored | |
418 | if mode == 0: #Divided in channels |
|
418 | if mode == 0: #Divided in channels | |
419 | arrayData = dataset.value.astype(numpy.float)[0][blockList] |
|
419 | arrayData = dataset.value.astype(numpy.float)[0][blockList] | |
420 | if mode == 1: #Divided in parameter |
|
420 | if mode == 1: #Divided in parameter | |
421 | strds = 'table' |
|
421 | strds = 'table' | |
422 | nDatas = nDim1 |
|
422 | nDatas = nDim1 | |
423 | newShapes = (blocksPerFile,nDim2,nDim0) |
|
423 | newShapes = (blocksPerFile,nDim2,nDim0) | |
424 | elif mode==2: #Concatenated in a table |
|
424 | elif mode==2: #Concatenated in a table | |
425 | strds = 'table0' |
|
425 | strds = 'table0' | |
426 | arrayData = dataset[strds].value |
|
426 | arrayData = dataset[strds].value | |
427 | #Selecting part of the dataset |
|
427 | #Selecting part of the dataset | |
428 | utctime = arrayData[:,0] |
|
428 | utctime = arrayData[:,0] | |
429 | u, indices = numpy.unique(utctime, return_index=True) |
|
429 | u, indices = numpy.unique(utctime, return_index=True) | |
430 |
|
430 | |||
431 | if blockList.size != indices.size: |
|
431 | if blockList.size != indices.size: | |
432 | indMin = indices[blockList[0]] |
|
432 | indMin = indices[blockList[0]] | |
433 | if blockList[1] + 1 >= indices.size: |
|
433 | if blockList[1] + 1 >= indices.size: | |
434 | arrayData = arrayData[indMin:,:] |
|
434 | arrayData = arrayData[indMin:,:] | |
435 | else: |
|
435 | else: | |
436 | indMax = indices[blockList[1] + 1] |
|
436 | indMax = indices[blockList[1] + 1] | |
437 | arrayData = arrayData[indMin:indMax,:] |
|
437 | arrayData = arrayData[indMin:indMax,:] | |
438 | return arrayData |
|
438 | return arrayData | |
439 |
|
439 | |||
440 | # One dimension |
|
440 | # One dimension | |
441 | if nDims == 0: |
|
441 | if nDims == 0: | |
442 | arrayData = dataset.value.astype(numpy.float)[0][blockList] |
|
442 | arrayData = dataset.value.astype(numpy.float)[0][blockList] | |
443 |
|
443 | |||
444 | # Two dimensions |
|
444 | # Two dimensions | |
445 | elif nDims == 2: |
|
445 | elif nDims == 2: | |
446 | arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0)) |
|
446 | arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0)) | |
447 | newShapes = (blocksPerFile,nDim0) |
|
447 | newShapes = (blocksPerFile,nDim0) | |
448 | nDatas = nDim1 |
|
448 | nDatas = nDim1 | |
449 |
|
449 | |||
450 | for i in range(nDatas): |
|
450 | for i in range(nDatas): | |
451 | data = dataset[strds + str(i)].value |
|
451 | data = dataset[strds + str(i)].value | |
452 | arrayData[:,i,:] = data[blockList,:] |
|
452 | arrayData[:,i,:] = data[blockList,:] | |
453 |
|
453 | |||
454 | # Three dimensions |
|
454 | # Three dimensions | |
455 | else: |
|
455 | else: | |
456 | arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0)) |
|
456 | arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0)) | |
457 | for i in range(nDatas): |
|
457 | for i in range(nDatas): | |
458 |
|
458 | |||
459 | data = dataset[strds + str(i)].value |
|
459 | data = dataset[strds + str(i)].value | |
460 |
|
460 | |||
461 | for b in range(blockList.size): |
|
461 | for b in range(blockList.size): | |
462 | arrayData[b,:,i,:] = data[:,:,blockList[b]] |
|
462 | arrayData[b,:,i,:] = data[:,:,blockList[b]] | |
463 |
|
463 | |||
464 | return arrayData |
|
464 | return arrayData | |
465 |
|
465 | |||
466 | def __setDataOut(self): |
|
466 | def __setDataOut(self): | |
467 | listMeta = self.listMeta |
|
467 | listMeta = self.listMeta | |
468 | listMetaname = self.listMetaname |
|
468 | listMetaname = self.listMetaname | |
469 | listDataname = self.listDataname |
|
469 | listDataname = self.listDataname | |
470 | listData = self.listData |
|
470 | listData = self.listData | |
471 | listShapes = self.listShapes |
|
471 | listShapes = self.listShapes | |
472 |
|
472 | |||
473 | blockIndex = self.blockIndex |
|
473 | blockIndex = self.blockIndex | |
474 | # blockList = self.blockList |
|
474 | # blockList = self.blockList | |
475 |
|
475 | |||
476 | for i in range(len(listMeta)): |
|
476 | for i in range(len(listMeta)): | |
477 | setattr(self.dataOut,listMetaname[i],listMeta[i]) |
|
477 | setattr(self.dataOut,listMetaname[i],listMeta[i]) | |
478 |
|
478 | |||
479 | for j in range(len(listData)): |
|
479 | for j in range(len(listData)): | |
480 | nShapes = listShapes[listDataname[j]][0] |
|
480 | nShapes = listShapes[listDataname[j]][0] | |
481 | mode = listShapes[listDataname[j]][4] |
|
481 | mode = listShapes[listDataname[j]][4] | |
482 | if nShapes == 1: |
|
482 | if nShapes == 1: | |
483 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex]) |
|
483 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex]) | |
484 | elif nShapes > 1: |
|
484 | elif nShapes > 1: | |
485 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:]) |
|
485 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:]) | |
486 | elif mode==0: |
|
486 | elif mode==0: | |
487 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex]) |
|
487 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex]) | |
488 | #Mode Meteors |
|
488 | #Mode Meteors | |
489 | elif mode ==2: |
|
489 | elif mode ==2: | |
490 | selectedData = self.__selectDataMode2(listData[j], blockIndex) |
|
490 | selectedData = self.__selectDataMode2(listData[j], blockIndex) | |
491 | setattr(self.dataOut, listDataname[j], selectedData) |
|
491 | setattr(self.dataOut, listDataname[j], selectedData) | |
492 | return |
|
492 | return | |
493 |
|
493 | |||
494 | def __selectDataMode2(self, data, blockIndex): |
|
494 | def __selectDataMode2(self, data, blockIndex): | |
495 | utctime = data[:,0] |
|
495 | utctime = data[:,0] | |
496 | aux, indices = numpy.unique(utctime, return_inverse=True) |
|
496 | aux, indices = numpy.unique(utctime, return_inverse=True) | |
497 | selInd = numpy.where(indices == blockIndex)[0] |
|
497 | selInd = numpy.where(indices == blockIndex)[0] | |
498 | selData = data[selInd,:] |
|
498 | selData = data[selInd,:] | |
499 |
|
499 | |||
500 | return selData |
|
500 | return selData | |
501 |
|
501 | |||
502 | def getData(self): |
|
502 | def getData(self): | |
503 |
|
503 | |||
504 | if self.blockIndex==self.blocksPerFile: |
|
504 | if self.blockIndex==self.blocksPerFile: | |
505 | if not( self.__setNextFileOffline() ): |
|
505 | if not( self.__setNextFileOffline() ): | |
506 | self.dataOut.flagNoData = True |
|
506 | self.dataOut.flagNoData = True | |
507 | return 0 |
|
507 | return 0 | |
508 |
|
508 | |||
509 | self.__setDataOut() |
|
509 | self.__setDataOut() | |
510 | self.dataOut.flagNoData = False |
|
510 | self.dataOut.flagNoData = False | |
511 |
|
511 | |||
512 | self.blockIndex += 1 |
|
512 | self.blockIndex += 1 | |
513 |
|
513 | |||
514 | return |
|
514 | return | |
515 |
|
515 | |||
516 | def run(self, **kwargs): |
|
516 | def run(self, **kwargs): | |
517 |
|
517 | |||
518 | if not(self.isConfig): |
|
518 | if not(self.isConfig): | |
519 | self.setup(**kwargs) |
|
519 | self.setup(**kwargs) | |
520 | # self.setObjProperties() |
|
520 | # self.setObjProperties() | |
521 | self.isConfig = True |
|
521 | self.isConfig = True | |
522 |
|
522 | |||
523 | self.getData() |
|
523 | self.getData() | |
524 |
|
524 | |||
525 | return |
|
525 | return | |
526 |
|
526 | |||
527 | @MPDecorator |
|
527 | @MPDecorator | |
528 | class ParamWriter(Operation): |
|
528 | class ParamWriter(Operation): | |
529 | ''' |
|
529 | ''' | |
530 | HDF5 Writer, stores parameters data in HDF5 format files |
|
530 | HDF5 Writer, stores parameters data in HDF5 format files | |
531 |
|
531 | |||
532 | path: path where the files will be stored |
|
532 | path: path where the files will be stored | |
533 |
|
533 | |||
534 | blocksPerFile: number of blocks that will be saved in per HDF5 format file |
|
534 | blocksPerFile: number of blocks that will be saved in per HDF5 format file | |
535 |
|
535 | |||
536 | mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors) |
|
536 | mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors) | |
537 |
|
537 | |||
538 | metadataList: list of attributes that will be stored as metadata |
|
538 | metadataList: list of attributes that will be stored as metadata | |
539 |
|
539 | |||
540 | dataList: list of attributes that will be stores as data |
|
540 | dataList: list of attributes that will be stores as data | |
541 |
|
541 | |||
542 | ''' |
|
542 | ''' | |
543 |
|
543 | |||
544 |
|
544 | |||
545 | ext = ".hdf5" |
|
545 | ext = ".hdf5" | |
546 | optchar = "D" |
|
546 | optchar = "D" | |
547 | metaoptchar = "M" |
|
547 | metaoptchar = "M" | |
548 | metaFile = None |
|
548 | metaFile = None | |
549 | filename = None |
|
549 | filename = None | |
550 | path = None |
|
550 | path = None | |
551 | setFile = None |
|
551 | setFile = None | |
552 | fp = None |
|
552 | fp = None | |
553 | grp = None |
|
553 | grp = None | |
554 | ds = None |
|
554 | ds = None | |
555 | firsttime = True |
|
555 | firsttime = True | |
556 | #Configurations |
|
556 | #Configurations | |
557 | blocksPerFile = None |
|
557 | blocksPerFile = None | |
558 | blockIndex = None |
|
558 | blockIndex = None | |
559 | dataOut = None |
|
559 | dataOut = None | |
560 | #Data Arrays |
|
560 | #Data Arrays | |
561 | dataList = None |
|
561 | dataList = None | |
562 | metadataList = None |
|
562 | metadataList = None | |
563 | dsList = None #List of dictionaries with dataset properties |
|
563 | dsList = None #List of dictionaries with dataset properties | |
564 | tableDim = None |
|
564 | tableDim = None | |
565 | dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')] |
|
565 | dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')] | |
566 | currentDay = None |
|
566 | currentDay = None | |
567 | lastTime = None |
|
567 | lastTime = None | |
|
568 | setType = None | |||
568 |
|
569 | |||
569 | def __init__(self): |
|
570 | def __init__(self): | |
570 |
|
571 | |||
571 | Operation.__init__(self) |
|
572 | Operation.__init__(self) | |
572 | return |
|
573 | return | |
573 |
|
574 | |||
574 | def setup(self, dataOut, path=None, blocksPerFile=10, metadataList=None, dataList=None, mode=None, setType=None): |
|
575 | def setup(self, dataOut, path=None, blocksPerFile=10, metadataList=None, dataList=None, mode=None, setType=None): | |
575 | self.path = path |
|
576 | self.path = path | |
576 | self.blocksPerFile = blocksPerFile |
|
577 | self.blocksPerFile = blocksPerFile | |
577 | self.metadataList = metadataList |
|
578 | self.metadataList = metadataList | |
578 | self.dataList = dataList |
|
579 | self.dataList = dataList | |
579 | self.dataOut = dataOut |
|
580 | self.dataOut = dataOut | |
580 | self.mode = mode |
|
581 | self.mode = mode | |
581 | if self.mode is not None: |
|
582 | if self.mode is not None: | |
582 | self.mode = numpy.zeros(len(self.dataList)) + mode |
|
583 | self.mode = numpy.zeros(len(self.dataList)) + mode | |
583 | else: |
|
584 | else: | |
584 | self.mode = numpy.ones(len(self.dataList)) |
|
585 | self.mode = numpy.ones(len(self.dataList)) | |
585 |
|
586 | |||
586 | self.setType = setType |
|
587 | self.setType = setType | |
587 |
|
588 | |||
588 | arrayDim = numpy.zeros((len(self.dataList),5)) |
|
589 | arrayDim = numpy.zeros((len(self.dataList),5)) | |
589 |
|
590 | |||
590 | #Table dimensions |
|
591 | #Table dimensions | |
591 | dtype0 = self.dtype |
|
592 | dtype0 = self.dtype | |
592 | tableList = [] |
|
593 | tableList = [] | |
593 |
|
594 | |||
594 | #Dictionary and list of tables |
|
595 | #Dictionary and list of tables | |
595 | dsList = [] |
|
596 | dsList = [] | |
596 |
|
597 | |||
597 | for i in range(len(self.dataList)): |
|
598 | for i in range(len(self.dataList)): | |
598 | dsDict = {} |
|
599 | dsDict = {} | |
599 | dataAux = getattr(self.dataOut, self.dataList[i]) |
|
600 | dataAux = getattr(self.dataOut, self.dataList[i]) | |
600 | dsDict['variable'] = self.dataList[i] |
|
601 | dsDict['variable'] = self.dataList[i] | |
601 | #--------------------- Conditionals ------------------------ |
|
602 | #--------------------- Conditionals ------------------------ | |
602 | #There is no data |
|
603 | #There is no data | |
603 |
|
604 | |||
604 | if dataAux is None: |
|
605 | if dataAux is None: | |
605 |
|
606 | |||
606 | return 0 |
|
607 | return 0 | |
607 |
|
608 | |||
608 | if isinstance(dataAux, (int, float, numpy.integer, numpy.float)): |
|
609 | if isinstance(dataAux, (int, float, numpy.integer, numpy.float)): | |
609 | dsDict['mode'] = 0 |
|
610 | dsDict['mode'] = 0 | |
610 | dsDict['nDim'] = 0 |
|
611 | dsDict['nDim'] = 0 | |
611 | arrayDim[i,0] = 0 |
|
612 | arrayDim[i,0] = 0 | |
612 | dsList.append(dsDict) |
|
613 | dsList.append(dsDict) | |
613 |
|
614 | |||
614 | #Mode 2: meteors |
|
615 | #Mode 2: meteors | |
615 | elif self.mode[i] == 2: |
|
616 | elif self.mode[i] == 2: | |
616 | dsDict['dsName'] = 'table0' |
|
617 | dsDict['dsName'] = 'table0' | |
617 | dsDict['mode'] = 2 # Mode meteors |
|
618 | dsDict['mode'] = 2 # Mode meteors | |
618 | dsDict['shape'] = dataAux.shape[-1] |
|
619 | dsDict['shape'] = dataAux.shape[-1] | |
619 | dsDict['nDim'] = 0 |
|
620 | dsDict['nDim'] = 0 | |
620 | dsDict['dsNumber'] = 1 |
|
621 | dsDict['dsNumber'] = 1 | |
621 | arrayDim[i,3] = dataAux.shape[-1] |
|
622 | arrayDim[i,3] = dataAux.shape[-1] | |
622 | arrayDim[i,4] = self.mode[i] #Mode the data was stored |
|
623 | arrayDim[i,4] = self.mode[i] #Mode the data was stored | |
623 | dsList.append(dsDict) |
|
624 | dsList.append(dsDict) | |
624 |
|
625 | |||
625 | #Mode 1 |
|
626 | #Mode 1 | |
626 | else: |
|
627 | else: | |
627 | arrayDim0 = dataAux.shape #Data dimensions |
|
628 | arrayDim0 = dataAux.shape #Data dimensions | |
628 | arrayDim[i,0] = len(arrayDim0) #Number of array dimensions |
|
629 | arrayDim[i,0] = len(arrayDim0) #Number of array dimensions | |
629 | arrayDim[i,4] = self.mode[i] #Mode the data was stored |
|
630 | arrayDim[i,4] = self.mode[i] #Mode the data was stored | |
630 | strtable = 'table' |
|
631 | strtable = 'table' | |
631 | dsDict['mode'] = 1 # Mode parameters |
|
632 | dsDict['mode'] = 1 # Mode parameters | |
632 |
|
633 | |||
633 | # Three-dimension arrays |
|
634 | # Three-dimension arrays | |
634 | if len(arrayDim0) == 3: |
|
635 | if len(arrayDim0) == 3: | |
635 | arrayDim[i,1:-1] = numpy.array(arrayDim0) |
|
636 | arrayDim[i,1:-1] = numpy.array(arrayDim0) | |
636 | nTables = int(arrayDim[i,2]) |
|
637 | nTables = int(arrayDim[i,2]) | |
637 | dsDict['dsNumber'] = nTables |
|
638 | dsDict['dsNumber'] = nTables | |
638 | dsDict['shape'] = arrayDim[i,2:4] |
|
639 | dsDict['shape'] = arrayDim[i,2:4] | |
639 | dsDict['nDim'] = 3 |
|
640 | dsDict['nDim'] = 3 | |
640 |
|
641 | |||
641 | for j in range(nTables): |
|
642 | for j in range(nTables): | |
642 | dsDict = dsDict.copy() |
|
643 | dsDict = dsDict.copy() | |
643 | dsDict['dsName'] = strtable + str(j) |
|
644 | dsDict['dsName'] = strtable + str(j) | |
644 | dsList.append(dsDict) |
|
645 | dsList.append(dsDict) | |
645 |
|
646 | |||
646 | # Two-dimension arrays |
|
647 | # Two-dimension arrays | |
647 | elif len(arrayDim0) == 2: |
|
648 | elif len(arrayDim0) == 2: | |
648 | arrayDim[i,2:-1] = numpy.array(arrayDim0) |
|
649 | arrayDim[i,2:-1] = numpy.array(arrayDim0) | |
649 | nTables = int(arrayDim[i,2]) |
|
650 | nTables = int(arrayDim[i,2]) | |
650 | dsDict['dsNumber'] = nTables |
|
651 | dsDict['dsNumber'] = nTables | |
651 | dsDict['shape'] = arrayDim[i,3] |
|
652 | dsDict['shape'] = arrayDim[i,3] | |
652 | dsDict['nDim'] = 2 |
|
653 | dsDict['nDim'] = 2 | |
653 |
|
654 | |||
654 | for j in range(nTables): |
|
655 | for j in range(nTables): | |
655 | dsDict = dsDict.copy() |
|
656 | dsDict = dsDict.copy() | |
656 | dsDict['dsName'] = strtable + str(j) |
|
657 | dsDict['dsName'] = strtable + str(j) | |
657 | dsList.append(dsDict) |
|
658 | dsList.append(dsDict) | |
658 |
|
659 | |||
659 | # One-dimension arrays |
|
660 | # One-dimension arrays | |
660 | elif len(arrayDim0) == 1: |
|
661 | elif len(arrayDim0) == 1: | |
661 | arrayDim[i,3] = arrayDim0[0] |
|
662 | arrayDim[i,3] = arrayDim0[0] | |
662 | dsDict['shape'] = arrayDim0[0] |
|
663 | dsDict['shape'] = arrayDim0[0] | |
663 | dsDict['dsNumber'] = 1 |
|
664 | dsDict['dsNumber'] = 1 | |
664 | dsDict['dsName'] = strtable + str(0) |
|
665 | dsDict['dsName'] = strtable + str(0) | |
665 | dsDict['nDim'] = 1 |
|
666 | dsDict['nDim'] = 1 | |
666 | dsList.append(dsDict) |
|
667 | dsList.append(dsDict) | |
667 |
|
668 | |||
668 | table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0) |
|
669 | table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0) | |
669 | tableList.append(table) |
|
670 | tableList.append(table) | |
670 |
|
671 | |||
671 | self.dsList = dsList |
|
672 | self.dsList = dsList | |
672 | self.tableDim = numpy.array(tableList, dtype = dtype0) |
|
673 | self.tableDim = numpy.array(tableList, dtype = dtype0) | |
673 | self.blockIndex = 0 |
|
674 | self.blockIndex = 0 | |
674 | timeTuple = time.localtime(dataOut.utctime) |
|
675 | timeTuple = time.localtime(dataOut.utctime) | |
675 | self.currentDay = timeTuple.tm_yday |
|
676 | self.currentDay = timeTuple.tm_yday | |
676 |
|
677 | |||
677 | def putMetadata(self): |
|
678 | def putMetadata(self): | |
678 |
|
679 | |||
679 | fp = self.createMetadataFile() |
|
680 | fp = self.createMetadataFile() | |
680 | self.writeMetadata(fp) |
|
681 | self.writeMetadata(fp) | |
681 | fp.close() |
|
682 | fp.close() | |
682 | return |
|
683 | return | |
683 |
|
684 | |||
684 | def createMetadataFile(self): |
|
685 | def createMetadataFile(self): | |
685 | ext = self.ext |
|
686 | ext = self.ext | |
686 | path = self.path |
|
687 | path = self.path | |
687 | setFile = self.setFile |
|
688 | setFile = self.setFile | |
688 |
|
689 | |||
689 | timeTuple = time.localtime(self.dataOut.utctime) |
|
690 | timeTuple = time.localtime(self.dataOut.utctime) | |
690 |
|
691 | |||
691 | subfolder = '' |
|
692 | subfolder = '' | |
692 | fullpath = os.path.join( path, subfolder ) |
|
693 | fullpath = os.path.join( path, subfolder ) | |
693 |
|
694 | |||
694 | if not( os.path.exists(fullpath) ): |
|
695 | if not( os.path.exists(fullpath) ): | |
695 | os.mkdir(fullpath) |
|
696 | os.mkdir(fullpath) | |
696 | setFile = -1 #inicializo mi contador de seteo |
|
697 | setFile = -1 #inicializo mi contador de seteo | |
697 |
|
698 | |||
698 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
699 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
699 | fullpath = os.path.join( path, subfolder ) |
|
700 | fullpath = os.path.join( path, subfolder ) | |
700 |
|
701 | |||
701 | if not( os.path.exists(fullpath) ): |
|
702 | if not( os.path.exists(fullpath) ): | |
702 | os.mkdir(fullpath) |
|
703 | os.mkdir(fullpath) | |
703 | setFile = -1 #inicializo mi contador de seteo |
|
704 | setFile = -1 #inicializo mi contador de seteo | |
704 |
|
705 | |||
705 | else: |
|
706 | else: | |
706 | filesList = os.listdir( fullpath ) |
|
707 | filesList = os.listdir( fullpath ) | |
707 | filesList = sorted( filesList, key=str.lower ) |
|
708 | filesList = sorted( filesList, key=str.lower ) | |
708 | if len( filesList ) > 0: |
|
709 | if len( filesList ) > 0: | |
709 | filesList = [k for k in filesList if k.startswith(self.metaoptchar)] |
|
710 | filesList = [k for k in filesList if k.startswith(self.metaoptchar)] | |
710 | filen = filesList[-1] |
|
711 | filen = filesList[-1] | |
711 | # el filename debera tener el siguiente formato |
|
712 | # el filename debera tener el siguiente formato | |
712 | # 0 1234 567 89A BCDE (hex) |
|
713 | # 0 1234 567 89A BCDE (hex) | |
713 | # x YYYY DDD SSS .ext |
|
714 | # x YYYY DDD SSS .ext | |
714 | if isNumber( filen[8:11] ): |
|
715 | if isNumber( filen[8:11] ): | |
715 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
716 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
716 | else: |
|
717 | else: | |
717 | setFile = -1 |
|
718 | setFile = -1 | |
718 | else: |
|
719 | else: | |
719 | setFile = -1 #inicializo mi contador de seteo |
|
720 | setFile = -1 #inicializo mi contador de seteo | |
720 |
|
721 | |||
721 | if self.setType is None: |
|
722 | if self.setType is None: | |
722 | setFile += 1 |
|
723 | setFile += 1 | |
723 | file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar, |
|
724 | file = '%s%4.4d%3.3d%03d%s' % (self.metaoptchar, | |
724 | timeTuple.tm_year, |
|
725 | timeTuple.tm_year, | |
725 | timeTuple.tm_yday, |
|
726 | timeTuple.tm_yday, | |
726 | setFile, |
|
727 | setFile, | |
727 | ext ) |
|
728 | ext ) | |
728 | else: |
|
729 | else: | |
729 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min |
|
730 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min | |
730 | file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar, |
|
731 | file = '%s%4.4d%3.3d%04d%s' % (self.metaoptchar, | |
731 | timeTuple.tm_year, |
|
732 | timeTuple.tm_year, | |
732 | timeTuple.tm_yday, |
|
733 | timeTuple.tm_yday, | |
733 | setFile, |
|
734 | setFile, | |
734 | ext ) |
|
735 | ext ) | |
735 |
|
736 | |||
736 | filename = os.path.join( path, subfolder, file ) |
|
737 | filename = os.path.join( path, subfolder, file ) | |
737 | self.metaFile = file |
|
738 | self.metaFile = file | |
738 | #Setting HDF5 File |
|
739 | #Setting HDF5 File | |
739 | fp = h5py.File(filename,'w') |
|
740 | fp = h5py.File(filename,'w') | |
740 |
|
741 | |||
741 | return fp |
|
742 | return fp | |
742 |
|
743 | |||
743 | def writeMetadata(self, fp): |
|
744 | def writeMetadata(self, fp): | |
744 |
|
745 | |||
745 | grp = fp.create_group("Metadata") |
|
746 | grp = fp.create_group("Metadata") | |
746 | grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype) |
|
747 | grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype) | |
747 |
|
748 | |||
748 | for i in range(len(self.metadataList)): |
|
749 | for i in range(len(self.metadataList)): | |
749 | grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i])) |
|
750 | grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i])) | |
750 | return |
|
751 | return | |
751 |
|
752 | |||
752 | def timeFlag(self): |
|
753 | def timeFlag(self): | |
753 | currentTime = self.dataOut.utctime |
|
754 | currentTime = self.dataOut.utctime | |
754 |
|
755 | |||
755 | if self.lastTime is None: |
|
756 | if self.lastTime is None: | |
756 | self.lastTime = currentTime |
|
757 | self.lastTime = currentTime | |
757 |
|
758 | |||
758 | #Day |
|
759 | #Day | |
759 | timeTuple = time.localtime(currentTime) |
|
760 | timeTuple = time.localtime(currentTime) | |
760 | dataDay = timeTuple.tm_yday |
|
761 | dataDay = timeTuple.tm_yday | |
761 |
|
762 | |||
762 | #Time |
|
763 | #Time | |
763 | timeDiff = currentTime - self.lastTime |
|
764 | timeDiff = currentTime - self.lastTime | |
764 |
|
765 | |||
765 | #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora |
|
766 | #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora | |
766 | if dataDay != self.currentDay: |
|
767 | if dataDay != self.currentDay: | |
767 | self.currentDay = dataDay |
|
768 | self.currentDay = dataDay | |
768 | return True |
|
769 | return True | |
769 | elif timeDiff > 3*60*60: |
|
770 | elif timeDiff > 3*60*60: | |
770 | self.lastTime = currentTime |
|
771 | self.lastTime = currentTime | |
771 | return True |
|
772 | return True | |
772 | else: |
|
773 | else: | |
773 | self.lastTime = currentTime |
|
774 | self.lastTime = currentTime | |
774 | return False |
|
775 | return False | |
775 |
|
776 | |||
776 | def setNextFile(self): |
|
777 | def setNextFile(self): | |
777 |
|
778 | |||
778 | ext = self.ext |
|
779 | ext = self.ext | |
779 | path = self.path |
|
780 | path = self.path | |
780 | setFile = self.setFile |
|
781 | setFile = self.setFile | |
781 | mode = self.mode |
|
782 | mode = self.mode | |
782 |
|
783 | |||
783 | timeTuple = time.localtime(self.dataOut.utctime) |
|
784 | timeTuple = time.localtime(self.dataOut.utctime) | |
784 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
785 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
785 |
|
786 | |||
786 | fullpath = os.path.join( path, subfolder ) |
|
787 | fullpath = os.path.join( path, subfolder ) | |
787 |
|
788 | |||
788 | if os.path.exists(fullpath): |
|
789 | if os.path.exists(fullpath): | |
789 | filesList = os.listdir( fullpath ) |
|
790 | filesList = os.listdir( fullpath ) | |
790 |
filesList = [k for k in filesList if k |
|
791 | filesList = [k for k in filesList if 'M' in k] | |
791 | if len( filesList ) > 0: |
|
792 | if len( filesList ) > 0: | |
792 | filesList = sorted( filesList, key=str.lower ) |
|
793 | filesList = sorted( filesList, key=str.lower ) | |
793 | filen = filesList[-1] |
|
794 | filen = filesList[-1] | |
794 | # el filename debera tener el siguiente formato |
|
795 | # el filename debera tener el siguiente formato | |
795 | # 0 1234 567 89A BCDE (hex) |
|
796 | # 0 1234 567 89A BCDE (hex) | |
796 | # x YYYY DDD SSS .ext |
|
797 | # x YYYY DDD SSS .ext | |
797 | if isNumber( filen[8:11] ): |
|
798 | if isNumber( filen[8:11] ): | |
798 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
799 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
799 | else: |
|
800 | else: | |
800 | setFile = -1 |
|
801 | setFile = -1 | |
801 | else: |
|
802 | else: | |
802 | setFile = -1 #inicializo mi contador de seteo |
|
803 | setFile = -1 #inicializo mi contador de seteo | |
803 | else: |
|
804 | else: | |
804 | os.makedirs(fullpath) |
|
805 | os.makedirs(fullpath) | |
805 | setFile = -1 #inicializo mi contador de seteo |
|
806 | setFile = -1 #inicializo mi contador de seteo | |
806 |
|
807 | |||
807 | if self.setType is None: |
|
808 | if self.setType is None: | |
808 | setFile += 1 |
|
809 | setFile += 1 | |
809 | file = '%s%4.4d%3.3d%03d%s' % (self.optchar, |
|
810 | file = '%s%4.4d%3.3d%03d%s' % (self.optchar, | |
810 | timeTuple.tm_year, |
|
811 | timeTuple.tm_year, | |
811 | timeTuple.tm_yday, |
|
812 | timeTuple.tm_yday, | |
812 | setFile, |
|
813 | setFile, | |
813 | ext ) |
|
814 | ext ) | |
814 | else: |
|
815 | else: | |
815 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min |
|
816 | setFile = timeTuple.tm_hour*60+timeTuple.tm_min | |
816 | file = '%s%4.4d%3.3d%04d%s' % (self.optchar, |
|
817 | file = '%s%4.4d%3.3d%04d%s' % (self.optchar, | |
817 | timeTuple.tm_year, |
|
818 | timeTuple.tm_year, | |
818 | timeTuple.tm_yday, |
|
819 | timeTuple.tm_yday, | |
819 | setFile, |
|
820 | setFile, | |
820 | ext ) |
|
821 | ext ) | |
821 |
|
822 | |||
822 | filename = os.path.join( path, subfolder, file ) |
|
823 | filename = os.path.join( path, subfolder, file ) | |
823 |
|
824 | |||
824 | #Setting HDF5 File |
|
825 | #Setting HDF5 File | |
825 | fp = h5py.File(filename,'w') |
|
826 | fp = h5py.File(filename,'w') | |
826 | #write metadata |
|
827 | #write metadata | |
827 | self.writeMetadata(fp) |
|
828 | self.writeMetadata(fp) | |
828 | #Write data |
|
829 | #Write data | |
829 | grp = fp.create_group("Data") |
|
830 | grp = fp.create_group("Data") | |
830 | ds = [] |
|
831 | ds = [] | |
831 | data = [] |
|
832 | data = [] | |
832 | dsList = self.dsList |
|
833 | dsList = self.dsList | |
833 | i = 0 |
|
834 | i = 0 | |
834 | while i < len(dsList): |
|
835 | while i < len(dsList): | |
835 | dsInfo = dsList[i] |
|
836 | dsInfo = dsList[i] | |
836 | #One-dimension data |
|
837 | #One-dimension data | |
837 | if dsInfo['mode'] == 0: |
|
838 | if dsInfo['mode'] == 0: | |
838 | ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64) |
|
839 | ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64) | |
839 | ds.append(ds0) |
|
840 | ds.append(ds0) | |
840 | data.append([]) |
|
841 | data.append([]) | |
841 | i += 1 |
|
842 | i += 1 | |
842 | continue |
|
843 | continue | |
843 |
|
844 | |||
844 | elif dsInfo['mode'] == 2: |
|
845 | elif dsInfo['mode'] == 2: | |
845 | grp0 = grp.create_group(dsInfo['variable']) |
|
846 | grp0 = grp.create_group(dsInfo['variable']) | |
846 | ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True) |
|
847 | ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True) | |
847 | ds.append(ds0) |
|
848 | ds.append(ds0) | |
848 | data.append([]) |
|
849 | data.append([]) | |
849 | i += 1 |
|
850 | i += 1 | |
850 | continue |
|
851 | continue | |
851 |
|
852 | |||
852 | elif dsInfo['mode'] == 1: |
|
853 | elif dsInfo['mode'] == 1: | |
853 | grp0 = grp.create_group(dsInfo['variable']) |
|
854 | grp0 = grp.create_group(dsInfo['variable']) | |
854 |
|
855 | |||
855 | for j in range(dsInfo['dsNumber']): |
|
856 | for j in range(dsInfo['dsNumber']): | |
856 | dsInfo = dsList[i] |
|
857 | dsInfo = dsList[i] | |
857 | tableName = dsInfo['dsName'] |
|
858 | tableName = dsInfo['dsName'] | |
858 |
|
859 | |||
859 |
|
860 | |||
860 | if dsInfo['nDim'] == 3: |
|
861 | if dsInfo['nDim'] == 3: | |
861 | shape = dsInfo['shape'].astype(int) |
|
862 | shape = dsInfo['shape'].astype(int) | |
862 | ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True) |
|
863 | ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True) | |
863 | else: |
|
864 | else: | |
864 | shape = int(dsInfo['shape']) |
|
865 | shape = int(dsInfo['shape']) | |
865 | ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True) |
|
866 | ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True) | |
866 |
|
867 | |||
867 | ds.append(ds0) |
|
868 | ds.append(ds0) | |
868 | data.append([]) |
|
869 | data.append([]) | |
869 | i += 1 |
|
870 | i += 1 | |
870 |
|
871 | |||
871 | fp.flush() |
|
872 | fp.flush() | |
872 | fp.close() |
|
873 | fp.close() | |
873 |
|
874 | |||
874 | log.log('creating file: {}'.format(filename), 'Writing') |
|
875 | log.log('creating file: {}'.format(filename), 'Writing') | |
875 | self.filename = filename |
|
876 | self.filename = filename | |
876 | self.ds = ds |
|
877 | self.ds = ds | |
877 | self.data = data |
|
878 | self.data = data | |
878 | self.firsttime = True |
|
879 | self.firsttime = True | |
879 | self.blockIndex = 0 |
|
880 | self.blockIndex = 0 | |
880 | return |
|
881 | return | |
881 |
|
882 | |||
882 | def putData(self): |
|
883 | def putData(self): | |
883 |
|
884 | |||
884 | if self.blockIndex == self.blocksPerFile or self.timeFlag(): |
|
885 | if self.blockIndex == self.blocksPerFile or self.timeFlag(): | |
885 | self.setNextFile() |
|
886 | self.setNextFile() | |
886 |
|
887 | |||
887 | self.readBlock() |
|
888 | self.readBlock() | |
888 | self.setBlock() #Prepare data to be written |
|
889 | self.setBlock() #Prepare data to be written | |
889 | self.writeBlock() #Write data |
|
890 | self.writeBlock() #Write data | |
890 |
|
891 | |||
891 | return |
|
892 | return | |
892 |
|
893 | |||
893 | def readBlock(self): |
|
894 | def readBlock(self): | |
894 |
|
895 | |||
895 | ''' |
|
896 | ''' | |
896 | data Array configured |
|
897 | data Array configured | |
897 |
|
898 | |||
898 |
|
899 | |||
899 | self.data |
|
900 | self.data | |
900 | ''' |
|
901 | ''' | |
901 | dsList = self.dsList |
|
902 | dsList = self.dsList | |
902 | ds = self.ds |
|
903 | ds = self.ds | |
903 | #Setting HDF5 File |
|
904 | #Setting HDF5 File | |
904 | fp = h5py.File(self.filename,'r+') |
|
905 | fp = h5py.File(self.filename,'r+') | |
905 | grp = fp["Data"] |
|
906 | grp = fp["Data"] | |
906 | ind = 0 |
|
907 | ind = 0 | |
907 |
|
908 | |||
908 | while ind < len(dsList): |
|
909 | while ind < len(dsList): | |
909 | dsInfo = dsList[ind] |
|
910 | dsInfo = dsList[ind] | |
910 |
|
911 | |||
911 | if dsInfo['mode'] == 0: |
|
912 | if dsInfo['mode'] == 0: | |
912 | ds0 = grp[dsInfo['variable']] |
|
913 | ds0 = grp[dsInfo['variable']] | |
913 | ds[ind] = ds0 |
|
914 | ds[ind] = ds0 | |
914 | ind += 1 |
|
915 | ind += 1 | |
915 | else: |
|
916 | else: | |
916 |
|
917 | |||
917 | grp0 = grp[dsInfo['variable']] |
|
918 | grp0 = grp[dsInfo['variable']] | |
918 |
|
919 | |||
919 | for j in range(dsInfo['dsNumber']): |
|
920 | for j in range(dsInfo['dsNumber']): | |
920 | dsInfo = dsList[ind] |
|
921 | dsInfo = dsList[ind] | |
921 | ds0 = grp0[dsInfo['dsName']] |
|
922 | ds0 = grp0[dsInfo['dsName']] | |
922 | ds[ind] = ds0 |
|
923 | ds[ind] = ds0 | |
923 | ind += 1 |
|
924 | ind += 1 | |
924 |
|
925 | |||
925 | self.fp = fp |
|
926 | self.fp = fp | |
926 | self.grp = grp |
|
927 | self.grp = grp | |
927 | self.ds = ds |
|
928 | self.ds = ds | |
928 |
|
929 | |||
929 | return |
|
930 | return | |
930 |
|
931 | |||
931 | def setBlock(self): |
|
932 | def setBlock(self): | |
932 | ''' |
|
933 | ''' | |
933 | data Array configured |
|
934 | data Array configured | |
934 |
|
935 | |||
935 |
|
936 | |||
936 | self.data |
|
937 | self.data | |
937 | ''' |
|
938 | ''' | |
938 | #Creating Arrays |
|
939 | #Creating Arrays | |
939 | dsList = self.dsList |
|
940 | dsList = self.dsList | |
940 | data = self.data |
|
941 | data = self.data | |
941 | ind = 0 |
|
942 | ind = 0 | |
942 |
|
943 | |||
943 | while ind < len(dsList): |
|
944 | while ind < len(dsList): | |
944 | dsInfo = dsList[ind] |
|
945 | dsInfo = dsList[ind] | |
945 | dataAux = getattr(self.dataOut, dsInfo['variable']) |
|
946 | dataAux = getattr(self.dataOut, dsInfo['variable']) | |
946 |
|
947 | |||
947 | mode = dsInfo['mode'] |
|
948 | mode = dsInfo['mode'] | |
948 | nDim = dsInfo['nDim'] |
|
949 | nDim = dsInfo['nDim'] | |
949 |
|
950 | |||
950 | if mode == 0 or mode == 2 or nDim == 1: |
|
951 | if mode == 0 or mode == 2 or nDim == 1: | |
951 | data[ind] = dataAux |
|
952 | data[ind] = dataAux | |
952 | ind += 1 |
|
953 | ind += 1 | |
953 | # elif nDim == 1: |
|
954 | # elif nDim == 1: | |
954 | # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1)) |
|
955 | # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1)) | |
955 | # ind += 1 |
|
956 | # ind += 1 | |
956 | elif nDim == 2: |
|
957 | elif nDim == 2: | |
957 | for j in range(dsInfo['dsNumber']): |
|
958 | for j in range(dsInfo['dsNumber']): | |
958 | data[ind] = dataAux[j,:] |
|
959 | data[ind] = dataAux[j,:] | |
959 | ind += 1 |
|
960 | ind += 1 | |
960 | elif nDim == 3: |
|
961 | elif nDim == 3: | |
961 | for j in range(dsInfo['dsNumber']): |
|
962 | for j in range(dsInfo['dsNumber']): | |
962 | data[ind] = dataAux[:,j,:] |
|
963 | data[ind] = dataAux[:,j,:] | |
963 | ind += 1 |
|
964 | ind += 1 | |
964 |
|
965 | |||
965 | self.data = data |
|
966 | self.data = data | |
966 | return |
|
967 | return | |
967 |
|
968 | |||
968 | def writeBlock(self): |
|
969 | def writeBlock(self): | |
969 | ''' |
|
970 | ''' | |
970 | Saves the block in the HDF5 file |
|
971 | Saves the block in the HDF5 file | |
971 | ''' |
|
972 | ''' | |
972 | dsList = self.dsList |
|
973 | dsList = self.dsList | |
973 |
|
974 | |||
974 | for i in range(len(self.ds)): |
|
975 | for i in range(len(self.ds)): | |
975 | dsInfo = dsList[i] |
|
976 | dsInfo = dsList[i] | |
976 | nDim = dsInfo['nDim'] |
|
977 | nDim = dsInfo['nDim'] | |
977 | mode = dsInfo['mode'] |
|
978 | mode = dsInfo['mode'] | |
978 |
|
979 | |||
979 | # First time |
|
980 | # First time | |
980 | if self.firsttime: |
|
981 | if self.firsttime: | |
981 | if type(self.data[i]) == numpy.ndarray: |
|
982 | if type(self.data[i]) == numpy.ndarray: | |
982 |
|
983 | |||
983 | if nDim == 3: |
|
984 | if nDim == 3: | |
984 | self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1)) |
|
985 | self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1)) | |
985 | self.ds[i].resize(self.data[i].shape) |
|
986 | self.ds[i].resize(self.data[i].shape) | |
986 | if mode == 2: |
|
987 | if mode == 2: | |
987 | self.ds[i].resize(self.data[i].shape) |
|
988 | self.ds[i].resize(self.data[i].shape) | |
988 | self.ds[i][:] = self.data[i] |
|
989 | self.ds[i][:] = self.data[i] | |
989 | else: |
|
990 | else: | |
990 |
|
991 | |||
991 | # From second time |
|
992 | # From second time | |
992 | # Meteors! |
|
993 | # Meteors! | |
993 | if mode == 2: |
|
994 | if mode == 2: | |
994 | dataShape = self.data[i].shape |
|
995 | dataShape = self.data[i].shape | |
995 | dsShape = self.ds[i].shape |
|
996 | dsShape = self.ds[i].shape | |
996 | self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1])) |
|
997 | self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1])) | |
997 | self.ds[i][dsShape[0]:,:] = self.data[i] |
|
998 | self.ds[i][dsShape[0]:,:] = self.data[i] | |
998 | # No dimension |
|
999 | # No dimension | |
999 | elif mode == 0: |
|
1000 | elif mode == 0: | |
1000 | self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1)) |
|
1001 | self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1)) | |
1001 | self.ds[i][0,-1] = self.data[i] |
|
1002 | self.ds[i][0,-1] = self.data[i] | |
1002 | # One dimension |
|
1003 | # One dimension | |
1003 | elif nDim == 1: |
|
1004 | elif nDim == 1: | |
1004 | self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1])) |
|
1005 | self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1])) | |
1005 | self.ds[i][-1,:] = self.data[i] |
|
1006 | self.ds[i][-1,:] = self.data[i] | |
1006 | # Two dimension |
|
1007 | # Two dimension | |
1007 | elif nDim == 2: |
|
1008 | elif nDim == 2: | |
1008 | self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1])) |
|
1009 | self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1])) | |
1009 | self.ds[i][self.blockIndex,:] = self.data[i] |
|
1010 | self.ds[i][self.blockIndex,:] = self.data[i] | |
1010 | # Three dimensions |
|
1011 | # Three dimensions | |
1011 | elif nDim == 3: |
|
1012 | elif nDim == 3: | |
1012 | self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1)) |
|
1013 | self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1)) | |
1013 | self.ds[i][:,:,-1] = self.data[i] |
|
1014 | self.ds[i][:,:,-1] = self.data[i] | |
1014 |
|
1015 | |||
1015 | self.firsttime = False |
|
1016 | self.firsttime = False | |
1016 | self.blockIndex += 1 |
|
1017 | self.blockIndex += 1 | |
1017 |
|
1018 | |||
1018 | #Close to save changes |
|
1019 | #Close to save changes | |
1019 | self.fp.flush() |
|
1020 | self.fp.flush() | |
1020 | self.fp.close() |
|
1021 | self.fp.close() | |
1021 | return |
|
1022 | return | |
1022 |
|
1023 | |||
1023 | def run(self, dataOut, path, blocksPerFile=10, metadataList=None, dataList=None, mode=None, setType=None): |
|
1024 | def run(self, dataOut, path, blocksPerFile=10, metadataList=None, dataList=None, mode=None, setType=None): | |
1024 |
|
1025 | |||
|
1026 | self.dataOut = dataOut | |||
1025 | if not(self.isConfig): |
|
1027 | if not(self.isConfig): | |
1026 | self.setup(dataOut, path=path, blocksPerFile=blocksPerFile, |
|
1028 | self.setup(dataOut, path=path, blocksPerFile=blocksPerFile, | |
1027 | metadataList=metadataList, dataList=dataList, mode=mode, |
|
1029 | metadataList=metadataList, dataList=dataList, mode=mode, | |
1028 | setType=setType) |
|
1030 | setType=setType) | |
1029 |
|
1031 | |||
1030 | self.isConfig = True |
|
1032 | self.isConfig = True | |
1031 | self.setNextFile() |
|
1033 | self.setNextFile() | |
1032 |
|
1034 | |||
1033 | self.putData() |
|
1035 | self.putData() | |
1034 | return |
|
1036 | return | |
1035 | No newline at end of file |
|
1037 |
@@ -1,1060 +1,1056 | |||||
1 | import itertools |
|
1 | import itertools | |
2 |
|
2 | |||
3 | import numpy |
|
3 | import numpy | |
4 |
|
4 | |||
5 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation |
|
5 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation | |
6 | from schainpy.model.data.jrodata import Spectra |
|
6 | from schainpy.model.data.jrodata import Spectra | |
7 | from schainpy.model.data.jrodata import hildebrand_sekhon |
|
7 | from schainpy.model.data.jrodata import hildebrand_sekhon | |
8 | from schainpy.utils import log |
|
8 | from schainpy.utils import log | |
9 |
|
9 | |||
10 | @MPDecorator |
|
10 | @MPDecorator | |
11 | class SpectraProc(ProcessingUnit): |
|
11 | class SpectraProc(ProcessingUnit): | |
12 |
|
12 | |||
13 |
|
13 | |||
14 | def __init__(self): |
|
14 | def __init__(self): | |
15 |
|
15 | |||
16 | ProcessingUnit.__init__(self) |
|
16 | ProcessingUnit.__init__(self) | |
17 |
|
17 | |||
18 | self.buffer = None |
|
18 | self.buffer = None | |
19 | self.firstdatatime = None |
|
19 | self.firstdatatime = None | |
20 | self.profIndex = 0 |
|
20 | self.profIndex = 0 | |
21 | self.dataOut = Spectra() |
|
21 | self.dataOut = Spectra() | |
22 | self.id_min = None |
|
22 | self.id_min = None | |
23 | self.id_max = None |
|
23 | self.id_max = None | |
24 | self.setupReq = False #Agregar a todas las unidades de proc |
|
24 | self.setupReq = False #Agregar a todas las unidades de proc | |
25 |
|
25 | |||
26 | def __updateSpecFromVoltage(self): |
|
26 | def __updateSpecFromVoltage(self): | |
27 |
|
27 | |||
28 | self.dataOut.timeZone = self.dataIn.timeZone |
|
28 | self.dataOut.timeZone = self.dataIn.timeZone | |
29 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
29 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
30 | self.dataOut.errorCount = self.dataIn.errorCount |
|
30 | self.dataOut.errorCount = self.dataIn.errorCount | |
31 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
31 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
32 | try: |
|
32 | try: | |
33 | self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy() |
|
33 | self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy() | |
34 | except: |
|
34 | except: | |
35 | pass |
|
35 | pass | |
36 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
36 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
37 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
37 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
38 | self.dataOut.channelList = self.dataIn.channelList |
|
38 | self.dataOut.channelList = self.dataIn.channelList | |
39 | self.dataOut.heightList = self.dataIn.heightList |
|
39 | self.dataOut.heightList = self.dataIn.heightList | |
40 | self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
40 | self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
41 |
|
41 | |||
42 | self.dataOut.nBaud = self.dataIn.nBaud |
|
42 | self.dataOut.nBaud = self.dataIn.nBaud | |
43 | self.dataOut.nCode = self.dataIn.nCode |
|
43 | self.dataOut.nCode = self.dataIn.nCode | |
44 | self.dataOut.code = self.dataIn.code |
|
44 | self.dataOut.code = self.dataIn.code | |
45 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
45 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
46 |
|
46 | |||
47 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
47 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
48 | self.dataOut.utctime = self.firstdatatime |
|
48 | self.dataOut.utctime = self.firstdatatime | |
49 | # asumo q la data esta decodificada |
|
49 | # asumo q la data esta decodificada | |
50 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData |
|
50 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData | |
51 | # asumo q la data esta sin flip |
|
51 | # asumo q la data esta sin flip | |
52 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData |
|
52 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData | |
53 | self.dataOut.flagShiftFFT = False |
|
53 | self.dataOut.flagShiftFFT = False | |
54 |
|
54 | |||
55 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
55 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
56 | self.dataOut.nIncohInt = 1 |
|
56 | self.dataOut.nIncohInt = 1 | |
57 |
|
57 | |||
58 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
58 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
59 |
|
59 | |||
60 | self.dataOut.frequency = self.dataIn.frequency |
|
60 | self.dataOut.frequency = self.dataIn.frequency | |
61 | self.dataOut.realtime = self.dataIn.realtime |
|
61 | self.dataOut.realtime = self.dataIn.realtime | |
62 |
|
62 | |||
63 | self.dataOut.azimuth = self.dataIn.azimuth |
|
63 | self.dataOut.azimuth = self.dataIn.azimuth | |
64 | self.dataOut.zenith = self.dataIn.zenith |
|
64 | self.dataOut.zenith = self.dataIn.zenith | |
65 |
|
65 | |||
66 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
66 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
67 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
67 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
68 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
68 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
69 |
|
69 | |||
70 | def __getFft(self): |
|
70 | def __getFft(self): | |
71 | """ |
|
71 | """ | |
72 | Convierte valores de Voltaje a Spectra |
|
72 | Convierte valores de Voltaje a Spectra | |
73 |
|
73 | |||
74 | Affected: |
|
74 | Affected: | |
75 | self.dataOut.data_spc |
|
75 | self.dataOut.data_spc | |
76 | self.dataOut.data_cspc |
|
76 | self.dataOut.data_cspc | |
77 | self.dataOut.data_dc |
|
77 | self.dataOut.data_dc | |
78 | self.dataOut.heightList |
|
78 | self.dataOut.heightList | |
79 | self.profIndex |
|
79 | self.profIndex | |
80 | self.buffer |
|
80 | self.buffer | |
81 | self.dataOut.flagNoData |
|
81 | self.dataOut.flagNoData | |
82 | """ |
|
82 | """ | |
83 | fft_volt = numpy.fft.fft( |
|
83 | fft_volt = numpy.fft.fft( | |
84 | self.buffer, n=self.dataOut.nFFTPoints, axis=1) |
|
84 | self.buffer, n=self.dataOut.nFFTPoints, axis=1) | |
85 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
85 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
86 | dc = fft_volt[:, 0, :] |
|
86 | dc = fft_volt[:, 0, :] | |
87 |
|
87 | |||
88 | # calculo de self-spectra |
|
88 | # calculo de self-spectra | |
89 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) |
|
89 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) | |
90 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
90 | spc = fft_volt * numpy.conjugate(fft_volt) | |
91 | spc = spc.real |
|
91 | spc = spc.real | |
92 |
|
92 | |||
93 | blocksize = 0 |
|
93 | blocksize = 0 | |
94 | blocksize += dc.size |
|
94 | blocksize += dc.size | |
95 | blocksize += spc.size |
|
95 | blocksize += spc.size | |
96 |
|
96 | |||
97 | cspc = None |
|
97 | cspc = None | |
98 | pairIndex = 0 |
|
98 | pairIndex = 0 | |
99 | if self.dataOut.pairsList != None: |
|
99 | if self.dataOut.pairsList != None: | |
100 | # calculo de cross-spectra |
|
100 | # calculo de cross-spectra | |
101 | cspc = numpy.zeros( |
|
101 | cspc = numpy.zeros( | |
102 | (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
102 | (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
103 | for pair in self.dataOut.pairsList: |
|
103 | for pair in self.dataOut.pairsList: | |
104 | if pair[0] not in self.dataOut.channelList: |
|
104 | if pair[0] not in self.dataOut.channelList: | |
105 | raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % ( |
|
105 | raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % ( | |
106 | str(pair), str(self.dataOut.channelList))) |
|
106 | str(pair), str(self.dataOut.channelList))) | |
107 | if pair[1] not in self.dataOut.channelList: |
|
107 | if pair[1] not in self.dataOut.channelList: | |
108 | raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % ( |
|
108 | raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % ( | |
109 | str(pair), str(self.dataOut.channelList))) |
|
109 | str(pair), str(self.dataOut.channelList))) | |
110 |
|
110 | |||
111 | cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \ |
|
111 | cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \ | |
112 | numpy.conjugate(fft_volt[pair[1], :, :]) |
|
112 | numpy.conjugate(fft_volt[pair[1], :, :]) | |
113 | pairIndex += 1 |
|
113 | pairIndex += 1 | |
114 | blocksize += cspc.size |
|
114 | blocksize += cspc.size | |
115 |
|
115 | |||
116 | self.dataOut.data_spc = spc |
|
116 | self.dataOut.data_spc = spc | |
117 | self.dataOut.data_cspc = cspc |
|
117 | self.dataOut.data_cspc = cspc | |
118 | self.dataOut.data_dc = dc |
|
118 | self.dataOut.data_dc = dc | |
119 | self.dataOut.blockSize = blocksize |
|
119 | self.dataOut.blockSize = blocksize | |
120 | self.dataOut.flagShiftFFT = True |
|
120 | self.dataOut.flagShiftFFT = True | |
121 |
|
121 | |||
122 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False): |
|
122 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False): | |
123 |
|
123 | |||
124 | if self.dataIn.type == "Spectra": |
|
124 | if self.dataIn.type == "Spectra": | |
125 | self.dataOut.copy(self.dataIn) |
|
125 | self.dataOut.copy(self.dataIn) | |
126 | if shift_fft: |
|
126 | if shift_fft: | |
127 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
127 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
128 | shift = int(self.dataOut.nFFTPoints/2) |
|
128 | shift = int(self.dataOut.nFFTPoints/2) | |
129 | self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1) |
|
129 | self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1) | |
130 |
|
130 | |||
131 | if self.dataOut.data_cspc is not None: |
|
131 | if self.dataOut.data_cspc is not None: | |
132 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
132 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
133 | self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1) |
|
133 | self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1) | |
134 |
|
134 | |||
135 | return True |
|
135 | return True | |
136 |
|
136 | |||
137 | if self.dataIn.type == "Voltage": |
|
137 | if self.dataIn.type == "Voltage": | |
138 |
|
138 | |||
139 | self.dataOut.flagNoData = True |
|
139 | self.dataOut.flagNoData = True | |
140 |
|
140 | |||
141 | if nFFTPoints == None: |
|
141 | if nFFTPoints == None: | |
142 | raise ValueError("This SpectraProc.run() need nFFTPoints input variable") |
|
142 | raise ValueError("This SpectraProc.run() need nFFTPoints input variable") | |
143 |
|
143 | |||
144 | if nProfiles == None: |
|
144 | if nProfiles == None: | |
145 | nProfiles = nFFTPoints |
|
145 | nProfiles = nFFTPoints | |
146 |
|
146 | |||
147 | if ippFactor == None: |
|
147 | if ippFactor == None: | |
148 | ippFactor = 1 |
|
148 | ippFactor = 1 | |
149 |
|
149 | |||
150 | self.dataOut.ippFactor = ippFactor |
|
150 | self.dataOut.ippFactor = ippFactor | |
151 |
|
151 | |||
152 | self.dataOut.nFFTPoints = nFFTPoints |
|
152 | self.dataOut.nFFTPoints = nFFTPoints | |
153 | self.dataOut.pairsList = pairsList |
|
153 | self.dataOut.pairsList = pairsList | |
154 |
|
154 | |||
155 | if self.buffer is None: |
|
155 | if self.buffer is None: | |
156 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
156 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
157 | nProfiles, |
|
157 | nProfiles, | |
158 | self.dataIn.nHeights), |
|
158 | self.dataIn.nHeights), | |
159 | dtype='complex') |
|
159 | dtype='complex') | |
160 |
|
160 | |||
161 | if self.dataIn.flagDataAsBlock: |
|
161 | if self.dataIn.flagDataAsBlock: | |
162 | nVoltProfiles = self.dataIn.data.shape[1] |
|
162 | nVoltProfiles = self.dataIn.data.shape[1] | |
163 |
|
163 | |||
164 | if nVoltProfiles == nProfiles: |
|
164 | if nVoltProfiles == nProfiles: | |
165 | self.buffer = self.dataIn.data.copy() |
|
165 | self.buffer = self.dataIn.data.copy() | |
166 | self.profIndex = nVoltProfiles |
|
166 | self.profIndex = nVoltProfiles | |
167 |
|
167 | |||
168 | elif nVoltProfiles < nProfiles: |
|
168 | elif nVoltProfiles < nProfiles: | |
169 |
|
169 | |||
170 | if self.profIndex == 0: |
|
170 | if self.profIndex == 0: | |
171 | self.id_min = 0 |
|
171 | self.id_min = 0 | |
172 | self.id_max = nVoltProfiles |
|
172 | self.id_max = nVoltProfiles | |
173 |
|
173 | |||
174 | self.buffer[:, self.id_min:self.id_max, |
|
174 | self.buffer[:, self.id_min:self.id_max, | |
175 | :] = self.dataIn.data |
|
175 | :] = self.dataIn.data | |
176 | self.profIndex += nVoltProfiles |
|
176 | self.profIndex += nVoltProfiles | |
177 | self.id_min += nVoltProfiles |
|
177 | self.id_min += nVoltProfiles | |
178 | self.id_max += nVoltProfiles |
|
178 | self.id_max += nVoltProfiles | |
179 | else: |
|
179 | else: | |
180 | raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % ( |
|
180 | raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % ( | |
181 | self.dataIn.type, self.dataIn.data.shape[1], nProfiles)) |
|
181 | self.dataIn.type, self.dataIn.data.shape[1], nProfiles)) | |
182 | self.dataOut.flagNoData = True |
|
182 | self.dataOut.flagNoData = True | |
183 | return 0 |
|
183 | return 0 | |
184 | else: |
|
184 | else: | |
185 | self.buffer[:, self.profIndex, :] = self.dataIn.data.copy() |
|
185 | self.buffer[:, self.profIndex, :] = self.dataIn.data.copy() | |
186 | self.profIndex += 1 |
|
186 | self.profIndex += 1 | |
187 |
|
187 | |||
188 | if self.firstdatatime == None: |
|
188 | if self.firstdatatime == None: | |
189 | self.firstdatatime = self.dataIn.utctime |
|
189 | self.firstdatatime = self.dataIn.utctime | |
190 |
|
190 | |||
191 | if self.profIndex == nProfiles: |
|
191 | if self.profIndex == nProfiles: | |
192 | self.__updateSpecFromVoltage() |
|
192 | self.__updateSpecFromVoltage() | |
193 | self.__getFft() |
|
193 | self.__getFft() | |
194 |
|
194 | |||
195 | self.dataOut.flagNoData = False |
|
195 | self.dataOut.flagNoData = False | |
196 | self.firstdatatime = None |
|
196 | self.firstdatatime = None | |
197 | self.profIndex = 0 |
|
197 | self.profIndex = 0 | |
198 |
|
198 | |||
199 | return True |
|
199 | return True | |
200 |
|
200 | |||
201 | raise ValueError("The type of input object '%s' is not valid" % ( |
|
201 | raise ValueError("The type of input object '%s' is not valid" % ( | |
202 | self.dataIn.type)) |
|
202 | self.dataIn.type)) | |
203 |
|
203 | |||
204 | def __selectPairs(self, pairsList): |
|
204 | def __selectPairs(self, pairsList): | |
205 |
|
205 | |||
206 | if not pairsList: |
|
206 | if not pairsList: | |
207 | return |
|
207 | return | |
208 |
|
208 | |||
209 | pairs = [] |
|
209 | pairs = [] | |
210 | pairsIndex = [] |
|
210 | pairsIndex = [] | |
211 |
|
211 | |||
212 | for pair in pairsList: |
|
212 | for pair in pairsList: | |
213 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: |
|
213 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: | |
214 | continue |
|
214 | continue | |
215 | pairs.append(pair) |
|
215 | pairs.append(pair) | |
216 | pairsIndex.append(pairs.index(pair)) |
|
216 | pairsIndex.append(pairs.index(pair)) | |
217 |
|
217 | |||
218 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] |
|
218 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] | |
219 | self.dataOut.pairsList = pairs |
|
219 | self.dataOut.pairsList = pairs | |
220 |
|
220 | |||
221 | return |
|
221 | return | |
222 |
|
222 | |||
223 | def __selectPairsByChannel(self, channelList=None): |
|
223 | def __selectPairsByChannel(self, channelList=None): | |
224 |
|
224 | |||
225 | if channelList == None: |
|
225 | if channelList == None: | |
226 | return |
|
226 | return | |
227 |
|
227 | |||
228 | pairsIndexListSelected = [] |
|
228 | pairsIndexListSelected = [] | |
229 | for pairIndex in self.dataOut.pairsIndexList: |
|
229 | for pairIndex in self.dataOut.pairsIndexList: | |
230 | # First pair |
|
230 | # First pair | |
231 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
231 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |
232 | continue |
|
232 | continue | |
233 | # Second pair |
|
233 | # Second pair | |
234 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
234 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |
235 | continue |
|
235 | continue | |
236 |
|
236 | |||
237 | pairsIndexListSelected.append(pairIndex) |
|
237 | pairsIndexListSelected.append(pairIndex) | |
238 |
|
238 | |||
239 | if not pairsIndexListSelected: |
|
239 | if not pairsIndexListSelected: | |
240 | self.dataOut.data_cspc = None |
|
240 | self.dataOut.data_cspc = None | |
241 | self.dataOut.pairsList = [] |
|
241 | self.dataOut.pairsList = [] | |
242 | return |
|
242 | return | |
243 |
|
243 | |||
244 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
244 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
245 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
245 | self.dataOut.pairsList = [self.dataOut.pairsList[i] | |
246 | for i in pairsIndexListSelected] |
|
246 | for i in pairsIndexListSelected] | |
247 |
|
247 | |||
248 | return |
|
248 | return | |
249 |
|
249 | |||
250 | def selectChannels(self, channelList): |
|
250 | def selectChannels(self, channelList): | |
251 |
|
251 | |||
252 | channelIndexList = [] |
|
252 | channelIndexList = [] | |
253 |
|
253 | |||
254 | for channel in channelList: |
|
254 | for channel in channelList: | |
255 | if channel not in self.dataOut.channelList: |
|
255 | if channel not in self.dataOut.channelList: | |
256 | raise ValueError("Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % ( |
|
256 | raise ValueError("Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % ( | |
257 | channel, str(self.dataOut.channelList))) |
|
257 | channel, str(self.dataOut.channelList))) | |
258 |
|
258 | |||
259 | index = self.dataOut.channelList.index(channel) |
|
259 | index = self.dataOut.channelList.index(channel) | |
260 | channelIndexList.append(index) |
|
260 | channelIndexList.append(index) | |
261 |
|
261 | |||
262 | self.selectChannelsByIndex(channelIndexList) |
|
262 | self.selectChannelsByIndex(channelIndexList) | |
263 |
|
263 | |||
264 | def selectChannelsByIndex(self, channelIndexList): |
|
264 | def selectChannelsByIndex(self, channelIndexList): | |
265 | """ |
|
265 | """ | |
266 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
266 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
267 |
|
267 | |||
268 | Input: |
|
268 | Input: | |
269 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
269 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
270 |
|
270 | |||
271 | Affected: |
|
271 | Affected: | |
272 | self.dataOut.data_spc |
|
272 | self.dataOut.data_spc | |
273 | self.dataOut.channelIndexList |
|
273 | self.dataOut.channelIndexList | |
274 | self.dataOut.nChannels |
|
274 | self.dataOut.nChannels | |
275 |
|
275 | |||
276 | Return: |
|
276 | Return: | |
277 | None |
|
277 | None | |
278 | """ |
|
278 | """ | |
279 |
|
279 | |||
280 | for channelIndex in channelIndexList: |
|
280 | for channelIndex in channelIndexList: | |
281 | if channelIndex not in self.dataOut.channelIndexList: |
|
281 | if channelIndex not in self.dataOut.channelIndexList: | |
282 | raise ValueError("Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % ( |
|
282 | raise ValueError("Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % ( | |
283 | channelIndex, self.dataOut.channelIndexList)) |
|
283 | channelIndex, self.dataOut.channelIndexList)) | |
284 |
|
284 | |||
285 | # nChannels = len(channelIndexList) |
|
|||
286 |
|
||||
287 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
285 | data_spc = self.dataOut.data_spc[channelIndexList, :] | |
288 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
286 | data_dc = self.dataOut.data_dc[channelIndexList, :] | |
289 |
|
287 | |||
290 | self.dataOut.data_spc = data_spc |
|
288 | self.dataOut.data_spc = data_spc | |
291 | self.dataOut.data_dc = data_dc |
|
289 | self.dataOut.data_dc = data_dc | |
292 |
|
290 | |||
293 | self.dataOut.channelList = [ |
|
291 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
294 |
|
|
292 | self.dataOut.channelList = range(len(channelIndexList)) | |
295 | # self.dataOut.nChannels = nChannels |
|
293 | self.__selectPairsByChannel(channelIndexList) | |
296 |
|
294 | |||
297 | self.__selectPairsByChannel(self.dataOut.channelList) |
|
|||
298 |
|
||||
299 | return 1 |
|
295 | return 1 | |
300 |
|
296 | |||
301 |
|
297 | |||
302 | def selectFFTs(self, minFFT, maxFFT ): |
|
298 | def selectFFTs(self, minFFT, maxFFT ): | |
303 | """ |
|
299 | """ | |
304 | Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango |
|
300 | Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango | |
305 | minFFT<= FFT <= maxFFT |
|
301 | minFFT<= FFT <= maxFFT | |
306 | """ |
|
302 | """ | |
307 |
|
303 | |||
308 | if (minFFT > maxFFT): |
|
304 | if (minFFT > maxFFT): | |
309 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)) |
|
305 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)) | |
310 |
|
306 | |||
311 | if (minFFT < self.dataOut.getFreqRange()[0]): |
|
307 | if (minFFT < self.dataOut.getFreqRange()[0]): | |
312 | minFFT = self.dataOut.getFreqRange()[0] |
|
308 | minFFT = self.dataOut.getFreqRange()[0] | |
313 |
|
309 | |||
314 | if (maxFFT > self.dataOut.getFreqRange()[-1]): |
|
310 | if (maxFFT > self.dataOut.getFreqRange()[-1]): | |
315 | maxFFT = self.dataOut.getFreqRange()[-1] |
|
311 | maxFFT = self.dataOut.getFreqRange()[-1] | |
316 |
|
312 | |||
317 | minIndex = 0 |
|
313 | minIndex = 0 | |
318 | maxIndex = 0 |
|
314 | maxIndex = 0 | |
319 | FFTs = self.dataOut.getFreqRange() |
|
315 | FFTs = self.dataOut.getFreqRange() | |
320 |
|
316 | |||
321 | inda = numpy.where(FFTs >= minFFT) |
|
317 | inda = numpy.where(FFTs >= minFFT) | |
322 | indb = numpy.where(FFTs <= maxFFT) |
|
318 | indb = numpy.where(FFTs <= maxFFT) | |
323 |
|
319 | |||
324 | try: |
|
320 | try: | |
325 | minIndex = inda[0][0] |
|
321 | minIndex = inda[0][0] | |
326 | except: |
|
322 | except: | |
327 | minIndex = 0 |
|
323 | minIndex = 0 | |
328 |
|
324 | |||
329 | try: |
|
325 | try: | |
330 | maxIndex = indb[0][-1] |
|
326 | maxIndex = indb[0][-1] | |
331 | except: |
|
327 | except: | |
332 | maxIndex = len(FFTs) |
|
328 | maxIndex = len(FFTs) | |
333 |
|
329 | |||
334 | self.selectFFTsByIndex(minIndex, maxIndex) |
|
330 | self.selectFFTsByIndex(minIndex, maxIndex) | |
335 |
|
331 | |||
336 | return 1 |
|
332 | return 1 | |
337 |
|
333 | |||
338 |
|
334 | |||
339 | def setH0(self, h0, deltaHeight = None): |
|
335 | def setH0(self, h0, deltaHeight = None): | |
340 |
|
336 | |||
341 | if not deltaHeight: |
|
337 | if not deltaHeight: | |
342 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
338 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
343 |
|
339 | |||
344 | nHeights = self.dataOut.nHeights |
|
340 | nHeights = self.dataOut.nHeights | |
345 |
|
341 | |||
346 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
342 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
347 |
|
343 | |||
348 | self.dataOut.heightList = newHeiRange |
|
344 | self.dataOut.heightList = newHeiRange | |
349 |
|
345 | |||
350 |
|
346 | |||
351 | def selectHeights(self, minHei, maxHei): |
|
347 | def selectHeights(self, minHei, maxHei): | |
352 | """ |
|
348 | """ | |
353 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
349 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
354 | minHei <= height <= maxHei |
|
350 | minHei <= height <= maxHei | |
355 |
|
351 | |||
356 | Input: |
|
352 | Input: | |
357 | minHei : valor minimo de altura a considerar |
|
353 | minHei : valor minimo de altura a considerar | |
358 | maxHei : valor maximo de altura a considerar |
|
354 | maxHei : valor maximo de altura a considerar | |
359 |
|
355 | |||
360 | Affected: |
|
356 | Affected: | |
361 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
357 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
362 |
|
358 | |||
363 | Return: |
|
359 | Return: | |
364 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
360 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
365 | """ |
|
361 | """ | |
366 |
|
362 | |||
367 |
|
363 | |||
368 | if (minHei > maxHei): |
|
364 | if (minHei > maxHei): | |
369 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)) |
|
365 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)) | |
370 |
|
366 | |||
371 | if (minHei < self.dataOut.heightList[0]): |
|
367 | if (minHei < self.dataOut.heightList[0]): | |
372 | minHei = self.dataOut.heightList[0] |
|
368 | minHei = self.dataOut.heightList[0] | |
373 |
|
369 | |||
374 | if (maxHei > self.dataOut.heightList[-1]): |
|
370 | if (maxHei > self.dataOut.heightList[-1]): | |
375 | maxHei = self.dataOut.heightList[-1] |
|
371 | maxHei = self.dataOut.heightList[-1] | |
376 |
|
372 | |||
377 | minIndex = 0 |
|
373 | minIndex = 0 | |
378 | maxIndex = 0 |
|
374 | maxIndex = 0 | |
379 | heights = self.dataOut.heightList |
|
375 | heights = self.dataOut.heightList | |
380 |
|
376 | |||
381 | inda = numpy.where(heights >= minHei) |
|
377 | inda = numpy.where(heights >= minHei) | |
382 | indb = numpy.where(heights <= maxHei) |
|
378 | indb = numpy.where(heights <= maxHei) | |
383 |
|
379 | |||
384 | try: |
|
380 | try: | |
385 | minIndex = inda[0][0] |
|
381 | minIndex = inda[0][0] | |
386 | except: |
|
382 | except: | |
387 | minIndex = 0 |
|
383 | minIndex = 0 | |
388 |
|
384 | |||
389 | try: |
|
385 | try: | |
390 | maxIndex = indb[0][-1] |
|
386 | maxIndex = indb[0][-1] | |
391 | except: |
|
387 | except: | |
392 | maxIndex = len(heights) |
|
388 | maxIndex = len(heights) | |
393 |
|
389 | |||
394 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
390 | self.selectHeightsByIndex(minIndex, maxIndex) | |
395 |
|
391 | |||
396 |
|
392 | |||
397 | return 1 |
|
393 | return 1 | |
398 |
|
394 | |||
399 | def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): |
|
395 | def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): | |
400 | newheis = numpy.where( |
|
396 | newheis = numpy.where( | |
401 | self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
397 | self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
402 |
|
398 | |||
403 | if hei_ref != None: |
|
399 | if hei_ref != None: | |
404 | newheis = numpy.where(self.dataOut.heightList > hei_ref) |
|
400 | newheis = numpy.where(self.dataOut.heightList > hei_ref) | |
405 |
|
401 | |||
406 | minIndex = min(newheis[0]) |
|
402 | minIndex = min(newheis[0]) | |
407 | maxIndex = max(newheis[0]) |
|
403 | maxIndex = max(newheis[0]) | |
408 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
404 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
409 | heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
405 | heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
410 |
|
406 | |||
411 | # determina indices |
|
407 | # determina indices | |
412 | nheis = int(self.dataOut.radarControllerHeaderObj.txB / |
|
408 | nheis = int(self.dataOut.radarControllerHeaderObj.txB / | |
413 | (self.dataOut.heightList[1] - self.dataOut.heightList[0])) |
|
409 | (self.dataOut.heightList[1] - self.dataOut.heightList[0])) | |
414 | avg_dB = 10 * \ |
|
410 | avg_dB = 10 * \ | |
415 | numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) |
|
411 | numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) | |
416 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
412 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
417 | beacon_heiIndexList = [] |
|
413 | beacon_heiIndexList = [] | |
418 | for val in avg_dB.tolist(): |
|
414 | for val in avg_dB.tolist(): | |
419 | if val >= beacon_dB[0]: |
|
415 | if val >= beacon_dB[0]: | |
420 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
416 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
421 |
|
417 | |||
422 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
418 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
423 | data_cspc = None |
|
419 | data_cspc = None | |
424 | if self.dataOut.data_cspc is not None: |
|
420 | if self.dataOut.data_cspc is not None: | |
425 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
421 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
426 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
422 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
427 |
|
423 | |||
428 | data_dc = None |
|
424 | data_dc = None | |
429 | if self.dataOut.data_dc is not None: |
|
425 | if self.dataOut.data_dc is not None: | |
430 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
426 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
431 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
427 | #data_dc = data_dc[:,beacon_heiIndexList] | |
432 |
|
428 | |||
433 | self.dataOut.data_spc = data_spc |
|
429 | self.dataOut.data_spc = data_spc | |
434 | self.dataOut.data_cspc = data_cspc |
|
430 | self.dataOut.data_cspc = data_cspc | |
435 | self.dataOut.data_dc = data_dc |
|
431 | self.dataOut.data_dc = data_dc | |
436 | self.dataOut.heightList = heightList |
|
432 | self.dataOut.heightList = heightList | |
437 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
433 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
438 |
|
434 | |||
439 | return 1 |
|
435 | return 1 | |
440 |
|
436 | |||
441 | def selectFFTsByIndex(self, minIndex, maxIndex): |
|
437 | def selectFFTsByIndex(self, minIndex, maxIndex): | |
442 | """ |
|
438 | """ | |
443 |
|
439 | |||
444 | """ |
|
440 | """ | |
445 |
|
441 | |||
446 | if (minIndex < 0) or (minIndex > maxIndex): |
|
442 | if (minIndex < 0) or (minIndex > maxIndex): | |
447 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
443 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
448 |
|
444 | |||
449 | if (maxIndex >= self.dataOut.nProfiles): |
|
445 | if (maxIndex >= self.dataOut.nProfiles): | |
450 | maxIndex = self.dataOut.nProfiles-1 |
|
446 | maxIndex = self.dataOut.nProfiles-1 | |
451 |
|
447 | |||
452 | #Spectra |
|
448 | #Spectra | |
453 | data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:] |
|
449 | data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:] | |
454 |
|
450 | |||
455 | data_cspc = None |
|
451 | data_cspc = None | |
456 | if self.dataOut.data_cspc is not None: |
|
452 | if self.dataOut.data_cspc is not None: | |
457 | data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:] |
|
453 | data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:] | |
458 |
|
454 | |||
459 | data_dc = None |
|
455 | data_dc = None | |
460 | if self.dataOut.data_dc is not None: |
|
456 | if self.dataOut.data_dc is not None: | |
461 | data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:] |
|
457 | data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:] | |
462 |
|
458 | |||
463 | self.dataOut.data_spc = data_spc |
|
459 | self.dataOut.data_spc = data_spc | |
464 | self.dataOut.data_cspc = data_cspc |
|
460 | self.dataOut.data_cspc = data_cspc | |
465 | self.dataOut.data_dc = data_dc |
|
461 | self.dataOut.data_dc = data_dc | |
466 |
|
462 | |||
467 | self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1]) |
|
463 | self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1]) | |
468 | self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1] |
|
464 | self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1] | |
469 | self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1] |
|
465 | self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1] | |
470 |
|
466 | |||
471 | return 1 |
|
467 | return 1 | |
472 |
|
468 | |||
473 |
|
469 | |||
474 |
|
470 | |||
475 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
471 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
476 | """ |
|
472 | """ | |
477 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
473 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
478 | minIndex <= index <= maxIndex |
|
474 | minIndex <= index <= maxIndex | |
479 |
|
475 | |||
480 | Input: |
|
476 | Input: | |
481 | minIndex : valor de indice minimo de altura a considerar |
|
477 | minIndex : valor de indice minimo de altura a considerar | |
482 | maxIndex : valor de indice maximo de altura a considerar |
|
478 | maxIndex : valor de indice maximo de altura a considerar | |
483 |
|
479 | |||
484 | Affected: |
|
480 | Affected: | |
485 | self.dataOut.data_spc |
|
481 | self.dataOut.data_spc | |
486 | self.dataOut.data_cspc |
|
482 | self.dataOut.data_cspc | |
487 | self.dataOut.data_dc |
|
483 | self.dataOut.data_dc | |
488 | self.dataOut.heightList |
|
484 | self.dataOut.heightList | |
489 |
|
485 | |||
490 | Return: |
|
486 | Return: | |
491 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
487 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
492 | """ |
|
488 | """ | |
493 |
|
489 | |||
494 | if (minIndex < 0) or (minIndex > maxIndex): |
|
490 | if (minIndex < 0) or (minIndex > maxIndex): | |
495 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
491 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( | |
496 | minIndex, maxIndex)) |
|
492 | minIndex, maxIndex)) | |
497 |
|
493 | |||
498 | if (maxIndex >= self.dataOut.nHeights): |
|
494 | if (maxIndex >= self.dataOut.nHeights): | |
499 | maxIndex = self.dataOut.nHeights - 1 |
|
495 | maxIndex = self.dataOut.nHeights - 1 | |
500 |
|
496 | |||
501 | # Spectra |
|
497 | # Spectra | |
502 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
498 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
503 |
|
499 | |||
504 | data_cspc = None |
|
500 | data_cspc = None | |
505 | if self.dataOut.data_cspc is not None: |
|
501 | if self.dataOut.data_cspc is not None: | |
506 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
502 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
507 |
|
503 | |||
508 | data_dc = None |
|
504 | data_dc = None | |
509 | if self.dataOut.data_dc is not None: |
|
505 | if self.dataOut.data_dc is not None: | |
510 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
506 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
511 |
|
507 | |||
512 | self.dataOut.data_spc = data_spc |
|
508 | self.dataOut.data_spc = data_spc | |
513 | self.dataOut.data_cspc = data_cspc |
|
509 | self.dataOut.data_cspc = data_cspc | |
514 | self.dataOut.data_dc = data_dc |
|
510 | self.dataOut.data_dc = data_dc | |
515 |
|
511 | |||
516 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
512 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
517 |
|
513 | |||
518 | return 1 |
|
514 | return 1 | |
519 |
|
515 | |||
520 | def removeDC(self, mode=2): |
|
516 | def removeDC(self, mode=2): | |
521 | jspectra = self.dataOut.data_spc |
|
517 | jspectra = self.dataOut.data_spc | |
522 | jcspectra = self.dataOut.data_cspc |
|
518 | jcspectra = self.dataOut.data_cspc | |
523 |
|
519 | |||
524 | num_chan = jspectra.shape[0] |
|
520 | num_chan = jspectra.shape[0] | |
525 | num_hei = jspectra.shape[2] |
|
521 | num_hei = jspectra.shape[2] | |
526 |
|
522 | |||
527 | if jcspectra is not None: |
|
523 | if jcspectra is not None: | |
528 | jcspectraExist = True |
|
524 | jcspectraExist = True | |
529 | num_pairs = jcspectra.shape[0] |
|
525 | num_pairs = jcspectra.shape[0] | |
530 | else: |
|
526 | else: | |
531 | jcspectraExist = False |
|
527 | jcspectraExist = False | |
532 |
|
528 | |||
533 | freq_dc = int(jspectra.shape[1] / 2) |
|
529 | freq_dc = int(jspectra.shape[1] / 2) | |
534 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc |
|
530 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc | |
535 | ind_vel = ind_vel.astype(int) |
|
531 | ind_vel = ind_vel.astype(int) | |
536 |
|
532 | |||
537 | if ind_vel[0] < 0: |
|
533 | if ind_vel[0] < 0: | |
538 | ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof |
|
534 | ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof | |
539 |
|
535 | |||
540 | if mode == 1: |
|
536 | if mode == 1: | |
541 | jspectra[:, freq_dc, :] = ( |
|
537 | jspectra[:, freq_dc, :] = ( | |
542 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION |
|
538 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION | |
543 |
|
539 | |||
544 | if jcspectraExist: |
|
540 | if jcspectraExist: | |
545 | jcspectra[:, freq_dc, :] = ( |
|
541 | jcspectra[:, freq_dc, :] = ( | |
546 | jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 |
|
542 | jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 | |
547 |
|
543 | |||
548 | if mode == 2: |
|
544 | if mode == 2: | |
549 |
|
545 | |||
550 | vel = numpy.array([-2, -1, 1, 2]) |
|
546 | vel = numpy.array([-2, -1, 1, 2]) | |
551 | xx = numpy.zeros([4, 4]) |
|
547 | xx = numpy.zeros([4, 4]) | |
552 |
|
548 | |||
553 | for fil in range(4): |
|
549 | for fil in range(4): | |
554 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) |
|
550 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) | |
555 |
|
551 | |||
556 | xx_inv = numpy.linalg.inv(xx) |
|
552 | xx_inv = numpy.linalg.inv(xx) | |
557 | xx_aux = xx_inv[0, :] |
|
553 | xx_aux = xx_inv[0, :] | |
558 |
|
554 | |||
559 | for ich in range(num_chan): |
|
555 | for ich in range(num_chan): | |
560 | yy = jspectra[ich, ind_vel, :] |
|
556 | yy = jspectra[ich, ind_vel, :] | |
561 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
557 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) | |
562 |
|
558 | |||
563 | junkid = jspectra[ich, freq_dc, :] <= 0 |
|
559 | junkid = jspectra[ich, freq_dc, :] <= 0 | |
564 | cjunkid = sum(junkid) |
|
560 | cjunkid = sum(junkid) | |
565 |
|
561 | |||
566 | if cjunkid.any(): |
|
562 | if cjunkid.any(): | |
567 | jspectra[ich, freq_dc, junkid.nonzero()] = ( |
|
563 | jspectra[ich, freq_dc, junkid.nonzero()] = ( | |
568 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 |
|
564 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 | |
569 |
|
565 | |||
570 | if jcspectraExist: |
|
566 | if jcspectraExist: | |
571 | for ip in range(num_pairs): |
|
567 | for ip in range(num_pairs): | |
572 | yy = jcspectra[ip, ind_vel, :] |
|
568 | yy = jcspectra[ip, ind_vel, :] | |
573 | jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
569 | jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) | |
574 |
|
570 | |||
575 | self.dataOut.data_spc = jspectra |
|
571 | self.dataOut.data_spc = jspectra | |
576 | self.dataOut.data_cspc = jcspectra |
|
572 | self.dataOut.data_cspc = jcspectra | |
577 |
|
573 | |||
578 | return 1 |
|
574 | return 1 | |
579 |
|
575 | |||
580 | def removeInterference2(self): |
|
576 | def removeInterference2(self): | |
581 |
|
577 | |||
582 | cspc = self.dataOut.data_cspc |
|
578 | cspc = self.dataOut.data_cspc | |
583 | spc = self.dataOut.data_spc |
|
579 | spc = self.dataOut.data_spc | |
584 | Heights = numpy.arange(cspc.shape[2]) |
|
580 | Heights = numpy.arange(cspc.shape[2]) | |
585 | realCspc = numpy.abs(cspc) |
|
581 | realCspc = numpy.abs(cspc) | |
586 |
|
582 | |||
587 | for i in range(cspc.shape[0]): |
|
583 | for i in range(cspc.shape[0]): | |
588 | LinePower= numpy.sum(realCspc[i], axis=0) |
|
584 | LinePower= numpy.sum(realCspc[i], axis=0) | |
589 | Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)] |
|
585 | Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)] | |
590 | SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ] |
|
586 | SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ] | |
591 | InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 ) |
|
587 | InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 ) | |
592 | InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)] |
|
588 | InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)] | |
593 | InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)] |
|
589 | InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)] | |
594 |
|
590 | |||
595 |
|
591 | |||
596 | InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) ) |
|
592 | InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) ) | |
597 | #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax])) |
|
593 | #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax])) | |
598 | if len(InterferenceRange)<int(cspc.shape[1]*0.3): |
|
594 | if len(InterferenceRange)<int(cspc.shape[1]*0.3): | |
599 | cspc[i,InterferenceRange,:] = numpy.NaN |
|
595 | cspc[i,InterferenceRange,:] = numpy.NaN | |
600 |
|
596 | |||
601 |
|
597 | |||
602 |
|
598 | |||
603 | self.dataOut.data_cspc = cspc |
|
599 | self.dataOut.data_cspc = cspc | |
604 |
|
600 | |||
605 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
601 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): | |
606 |
|
602 | |||
607 | jspectra = self.dataOut.data_spc |
|
603 | jspectra = self.dataOut.data_spc | |
608 | jcspectra = self.dataOut.data_cspc |
|
604 | jcspectra = self.dataOut.data_cspc | |
609 | jnoise = self.dataOut.getNoise() |
|
605 | jnoise = self.dataOut.getNoise() | |
610 | num_incoh = self.dataOut.nIncohInt |
|
606 | num_incoh = self.dataOut.nIncohInt | |
611 |
|
607 | |||
612 | num_channel = jspectra.shape[0] |
|
608 | num_channel = jspectra.shape[0] | |
613 | num_prof = jspectra.shape[1] |
|
609 | num_prof = jspectra.shape[1] | |
614 | num_hei = jspectra.shape[2] |
|
610 | num_hei = jspectra.shape[2] | |
615 |
|
611 | |||
616 | # hei_interf |
|
612 | # hei_interf | |
617 | if hei_interf is None: |
|
613 | if hei_interf is None: | |
618 | count_hei = int(num_hei / 2) |
|
614 | count_hei = int(num_hei / 2) | |
619 | hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei |
|
615 | hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei | |
620 | hei_interf = numpy.asarray(hei_interf)[0] |
|
616 | hei_interf = numpy.asarray(hei_interf)[0] | |
621 | # nhei_interf |
|
617 | # nhei_interf | |
622 | if (nhei_interf == None): |
|
618 | if (nhei_interf == None): | |
623 | nhei_interf = 5 |
|
619 | nhei_interf = 5 | |
624 | if (nhei_interf < 1): |
|
620 | if (nhei_interf < 1): | |
625 | nhei_interf = 1 |
|
621 | nhei_interf = 1 | |
626 | if (nhei_interf > count_hei): |
|
622 | if (nhei_interf > count_hei): | |
627 | nhei_interf = count_hei |
|
623 | nhei_interf = count_hei | |
628 | if (offhei_interf == None): |
|
624 | if (offhei_interf == None): | |
629 | offhei_interf = 0 |
|
625 | offhei_interf = 0 | |
630 |
|
626 | |||
631 | ind_hei = list(range(num_hei)) |
|
627 | ind_hei = list(range(num_hei)) | |
632 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
628 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
633 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
629 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
634 | mask_prof = numpy.asarray(list(range(num_prof))) |
|
630 | mask_prof = numpy.asarray(list(range(num_prof))) | |
635 | num_mask_prof = mask_prof.size |
|
631 | num_mask_prof = mask_prof.size | |
636 | comp_mask_prof = [0, num_prof / 2] |
|
632 | comp_mask_prof = [0, num_prof / 2] | |
637 |
|
633 | |||
638 | # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
634 | # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
639 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
635 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
640 | jnoise = numpy.nan |
|
636 | jnoise = numpy.nan | |
641 | noise_exist = jnoise[0] < numpy.Inf |
|
637 | noise_exist = jnoise[0] < numpy.Inf | |
642 |
|
638 | |||
643 | # Subrutina de Remocion de la Interferencia |
|
639 | # Subrutina de Remocion de la Interferencia | |
644 | for ich in range(num_channel): |
|
640 | for ich in range(num_channel): | |
645 | # Se ordena los espectros segun su potencia (menor a mayor) |
|
641 | # Se ordena los espectros segun su potencia (menor a mayor) | |
646 | power = jspectra[ich, mask_prof, :] |
|
642 | power = jspectra[ich, mask_prof, :] | |
647 | power = power[:, hei_interf] |
|
643 | power = power[:, hei_interf] | |
648 | power = power.sum(axis=0) |
|
644 | power = power.sum(axis=0) | |
649 | psort = power.ravel().argsort() |
|
645 | psort = power.ravel().argsort() | |
650 |
|
646 | |||
651 | # Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
647 | # Se estima la interferencia promedio en los Espectros de Potencia empleando | |
652 | junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range( |
|
648 | junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range( | |
653 | offhei_interf, nhei_interf + offhei_interf))]]] |
|
649 | offhei_interf, nhei_interf + offhei_interf))]]] | |
654 |
|
650 | |||
655 | if noise_exist: |
|
651 | if noise_exist: | |
656 | # tmp_noise = jnoise[ich] / num_prof |
|
652 | # tmp_noise = jnoise[ich] / num_prof | |
657 | tmp_noise = jnoise[ich] |
|
653 | tmp_noise = jnoise[ich] | |
658 | junkspc_interf = junkspc_interf - tmp_noise |
|
654 | junkspc_interf = junkspc_interf - tmp_noise | |
659 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
655 | #junkspc_interf[:,comp_mask_prof] = 0 | |
660 |
|
656 | |||
661 | jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf |
|
657 | jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf | |
662 | jspc_interf = jspc_interf.transpose() |
|
658 | jspc_interf = jspc_interf.transpose() | |
663 | # Calculando el espectro de interferencia promedio |
|
659 | # Calculando el espectro de interferencia promedio | |
664 | noiseid = numpy.where( |
|
660 | noiseid = numpy.where( | |
665 | jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) |
|
661 | jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) | |
666 | noiseid = noiseid[0] |
|
662 | noiseid = noiseid[0] | |
667 | cnoiseid = noiseid.size |
|
663 | cnoiseid = noiseid.size | |
668 | interfid = numpy.where( |
|
664 | interfid = numpy.where( | |
669 | jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) |
|
665 | jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) | |
670 | interfid = interfid[0] |
|
666 | interfid = interfid[0] | |
671 | cinterfid = interfid.size |
|
667 | cinterfid = interfid.size | |
672 |
|
668 | |||
673 | if (cnoiseid > 0): |
|
669 | if (cnoiseid > 0): | |
674 | jspc_interf[noiseid] = 0 |
|
670 | jspc_interf[noiseid] = 0 | |
675 |
|
671 | |||
676 | # Expandiendo los perfiles a limpiar |
|
672 | # Expandiendo los perfiles a limpiar | |
677 | if (cinterfid > 0): |
|
673 | if (cinterfid > 0): | |
678 | new_interfid = ( |
|
674 | new_interfid = ( | |
679 | numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof |
|
675 | numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof | |
680 | new_interfid = numpy.asarray(new_interfid) |
|
676 | new_interfid = numpy.asarray(new_interfid) | |
681 | new_interfid = {x for x in new_interfid} |
|
677 | new_interfid = {x for x in new_interfid} | |
682 | new_interfid = numpy.array(list(new_interfid)) |
|
678 | new_interfid = numpy.array(list(new_interfid)) | |
683 | new_cinterfid = new_interfid.size |
|
679 | new_cinterfid = new_interfid.size | |
684 | else: |
|
680 | else: | |
685 | new_cinterfid = 0 |
|
681 | new_cinterfid = 0 | |
686 |
|
682 | |||
687 | for ip in range(new_cinterfid): |
|
683 | for ip in range(new_cinterfid): | |
688 | ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() |
|
684 | ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() | |
689 | jspc_interf[new_interfid[ip] |
|
685 | jspc_interf[new_interfid[ip] | |
690 | ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]] |
|
686 | ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]] | |
691 |
|
687 | |||
692 | jspectra[ich, :, ind_hei] = jspectra[ich, :, |
|
688 | jspectra[ich, :, ind_hei] = jspectra[ich, :, | |
693 | ind_hei] - jspc_interf # Corregir indices |
|
689 | ind_hei] - jspc_interf # Corregir indices | |
694 |
|
690 | |||
695 | # Removiendo la interferencia del punto de mayor interferencia |
|
691 | # Removiendo la interferencia del punto de mayor interferencia | |
696 | ListAux = jspc_interf[mask_prof].tolist() |
|
692 | ListAux = jspc_interf[mask_prof].tolist() | |
697 | maxid = ListAux.index(max(ListAux)) |
|
693 | maxid = ListAux.index(max(ListAux)) | |
698 |
|
694 | |||
699 | if cinterfid > 0: |
|
695 | if cinterfid > 0: | |
700 | for ip in range(cinterfid * (interf == 2) - 1): |
|
696 | for ip in range(cinterfid * (interf == 2) - 1): | |
701 | ind = (jspectra[ich, interfid[ip], :] < tmp_noise * |
|
697 | ind = (jspectra[ich, interfid[ip], :] < tmp_noise * | |
702 | (1 + 1 / numpy.sqrt(num_incoh))).nonzero() |
|
698 | (1 + 1 / numpy.sqrt(num_incoh))).nonzero() | |
703 | cind = len(ind) |
|
699 | cind = len(ind) | |
704 |
|
700 | |||
705 | if (cind > 0): |
|
701 | if (cind > 0): | |
706 | jspectra[ich, interfid[ip], ind] = tmp_noise * \ |
|
702 | jspectra[ich, interfid[ip], ind] = tmp_noise * \ | |
707 | (1 + (numpy.random.uniform(cind) - 0.5) / |
|
703 | (1 + (numpy.random.uniform(cind) - 0.5) / | |
708 | numpy.sqrt(num_incoh)) |
|
704 | numpy.sqrt(num_incoh)) | |
709 |
|
705 | |||
710 | ind = numpy.array([-2, -1, 1, 2]) |
|
706 | ind = numpy.array([-2, -1, 1, 2]) | |
711 | xx = numpy.zeros([4, 4]) |
|
707 | xx = numpy.zeros([4, 4]) | |
712 |
|
708 | |||
713 | for id1 in range(4): |
|
709 | for id1 in range(4): | |
714 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) |
|
710 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) | |
715 |
|
711 | |||
716 | xx_inv = numpy.linalg.inv(xx) |
|
712 | xx_inv = numpy.linalg.inv(xx) | |
717 | xx = xx_inv[:, 0] |
|
713 | xx = xx_inv[:, 0] | |
718 | ind = (ind + maxid + num_mask_prof) % num_mask_prof |
|
714 | ind = (ind + maxid + num_mask_prof) % num_mask_prof | |
719 | yy = jspectra[ich, mask_prof[ind], :] |
|
715 | yy = jspectra[ich, mask_prof[ind], :] | |
720 | jspectra[ich, mask_prof[maxid], :] = numpy.dot( |
|
716 | jspectra[ich, mask_prof[maxid], :] = numpy.dot( | |
721 | yy.transpose(), xx) |
|
717 | yy.transpose(), xx) | |
722 |
|
718 | |||
723 | indAux = (jspectra[ich, :, :] < tmp_noise * |
|
719 | indAux = (jspectra[ich, :, :] < tmp_noise * | |
724 | (1 - 1 / numpy.sqrt(num_incoh))).nonzero() |
|
720 | (1 - 1 / numpy.sqrt(num_incoh))).nonzero() | |
725 | jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ |
|
721 | jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ | |
726 | (1 - 1 / numpy.sqrt(num_incoh)) |
|
722 | (1 - 1 / numpy.sqrt(num_incoh)) | |
727 |
|
723 | |||
728 | # Remocion de Interferencia en el Cross Spectra |
|
724 | # Remocion de Interferencia en el Cross Spectra | |
729 | if jcspectra is None: |
|
725 | if jcspectra is None: | |
730 | return jspectra, jcspectra |
|
726 | return jspectra, jcspectra | |
731 | num_pairs = int(jcspectra.size / (num_prof * num_hei)) |
|
727 | num_pairs = int(jcspectra.size / (num_prof * num_hei)) | |
732 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
728 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
733 |
|
729 | |||
734 | for ip in range(num_pairs): |
|
730 | for ip in range(num_pairs): | |
735 |
|
731 | |||
736 | #------------------------------------------- |
|
732 | #------------------------------------------- | |
737 |
|
733 | |||
738 | cspower = numpy.abs(jcspectra[ip, mask_prof, :]) |
|
734 | cspower = numpy.abs(jcspectra[ip, mask_prof, :]) | |
739 | cspower = cspower[:, hei_interf] |
|
735 | cspower = cspower[:, hei_interf] | |
740 | cspower = cspower.sum(axis=0) |
|
736 | cspower = cspower.sum(axis=0) | |
741 |
|
737 | |||
742 | cspsort = cspower.ravel().argsort() |
|
738 | cspsort = cspower.ravel().argsort() | |
743 | junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range( |
|
739 | junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range( | |
744 | offhei_interf, nhei_interf + offhei_interf))]]] |
|
740 | offhei_interf, nhei_interf + offhei_interf))]]] | |
745 | junkcspc_interf = junkcspc_interf.transpose() |
|
741 | junkcspc_interf = junkcspc_interf.transpose() | |
746 | jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf |
|
742 | jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf | |
747 |
|
743 | |||
748 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
744 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
749 |
|
745 | |||
750 | median_real = int(numpy.median(numpy.real( |
|
746 | median_real = int(numpy.median(numpy.real( | |
751 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) |
|
747 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) | |
752 | median_imag = int(numpy.median(numpy.imag( |
|
748 | median_imag = int(numpy.median(numpy.imag( | |
753 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) |
|
749 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) | |
754 | comp_mask_prof = [int(e) for e in comp_mask_prof] |
|
750 | comp_mask_prof = [int(e) for e in comp_mask_prof] | |
755 | junkcspc_interf[comp_mask_prof, :] = numpy.complex( |
|
751 | junkcspc_interf[comp_mask_prof, :] = numpy.complex( | |
756 | median_real, median_imag) |
|
752 | median_real, median_imag) | |
757 |
|
753 | |||
758 | for iprof in range(num_prof): |
|
754 | for iprof in range(num_prof): | |
759 | ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() |
|
755 | ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() | |
760 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]] |
|
756 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]] | |
761 |
|
757 | |||
762 | # Removiendo la Interferencia |
|
758 | # Removiendo la Interferencia | |
763 | jcspectra[ip, :, ind_hei] = jcspectra[ip, |
|
759 | jcspectra[ip, :, ind_hei] = jcspectra[ip, | |
764 | :, ind_hei] - jcspc_interf |
|
760 | :, ind_hei] - jcspc_interf | |
765 |
|
761 | |||
766 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
762 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
767 | maxid = ListAux.index(max(ListAux)) |
|
763 | maxid = ListAux.index(max(ListAux)) | |
768 |
|
764 | |||
769 | ind = numpy.array([-2, -1, 1, 2]) |
|
765 | ind = numpy.array([-2, -1, 1, 2]) | |
770 | xx = numpy.zeros([4, 4]) |
|
766 | xx = numpy.zeros([4, 4]) | |
771 |
|
767 | |||
772 | for id1 in range(4): |
|
768 | for id1 in range(4): | |
773 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) |
|
769 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) | |
774 |
|
770 | |||
775 | xx_inv = numpy.linalg.inv(xx) |
|
771 | xx_inv = numpy.linalg.inv(xx) | |
776 | xx = xx_inv[:, 0] |
|
772 | xx = xx_inv[:, 0] | |
777 |
|
773 | |||
778 | ind = (ind + maxid + num_mask_prof) % num_mask_prof |
|
774 | ind = (ind + maxid + num_mask_prof) % num_mask_prof | |
779 | yy = jcspectra[ip, mask_prof[ind], :] |
|
775 | yy = jcspectra[ip, mask_prof[ind], :] | |
780 | jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx) |
|
776 | jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx) | |
781 |
|
777 | |||
782 | # Guardar Resultados |
|
778 | # Guardar Resultados | |
783 | self.dataOut.data_spc = jspectra |
|
779 | self.dataOut.data_spc = jspectra | |
784 | self.dataOut.data_cspc = jcspectra |
|
780 | self.dataOut.data_cspc = jcspectra | |
785 |
|
781 | |||
786 | return 1 |
|
782 | return 1 | |
787 |
|
783 | |||
788 | def setRadarFrequency(self, frequency=None): |
|
784 | def setRadarFrequency(self, frequency=None): | |
789 |
|
785 | |||
790 | if frequency != None: |
|
786 | if frequency != None: | |
791 | self.dataOut.frequency = frequency |
|
787 | self.dataOut.frequency = frequency | |
792 |
|
788 | |||
793 | return 1 |
|
789 | return 1 | |
794 |
|
790 | |||
795 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
791 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
796 | # validacion de rango |
|
792 | # validacion de rango | |
797 | if minHei == None: |
|
793 | if minHei == None: | |
798 | minHei = self.dataOut.heightList[0] |
|
794 | minHei = self.dataOut.heightList[0] | |
799 |
|
795 | |||
800 | if maxHei == None: |
|
796 | if maxHei == None: | |
801 | maxHei = self.dataOut.heightList[-1] |
|
797 | maxHei = self.dataOut.heightList[-1] | |
802 |
|
798 | |||
803 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
799 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
804 | print('minHei: %.2f is out of the heights range' % (minHei)) |
|
800 | print('minHei: %.2f is out of the heights range' % (minHei)) | |
805 | print('minHei is setting to %.2f' % (self.dataOut.heightList[0])) |
|
801 | print('minHei is setting to %.2f' % (self.dataOut.heightList[0])) | |
806 | minHei = self.dataOut.heightList[0] |
|
802 | minHei = self.dataOut.heightList[0] | |
807 |
|
803 | |||
808 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
804 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
809 | print('maxHei: %.2f is out of the heights range' % (maxHei)) |
|
805 | print('maxHei: %.2f is out of the heights range' % (maxHei)) | |
810 | print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1])) |
|
806 | print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1])) | |
811 | maxHei = self.dataOut.heightList[-1] |
|
807 | maxHei = self.dataOut.heightList[-1] | |
812 |
|
808 | |||
813 | # validacion de velocidades |
|
809 | # validacion de velocidades | |
814 | velrange = self.dataOut.getVelRange(1) |
|
810 | velrange = self.dataOut.getVelRange(1) | |
815 |
|
811 | |||
816 | if minVel == None: |
|
812 | if minVel == None: | |
817 | minVel = velrange[0] |
|
813 | minVel = velrange[0] | |
818 |
|
814 | |||
819 | if maxVel == None: |
|
815 | if maxVel == None: | |
820 | maxVel = velrange[-1] |
|
816 | maxVel = velrange[-1] | |
821 |
|
817 | |||
822 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
818 | if (minVel < velrange[0]) or (minVel > maxVel): | |
823 | print('minVel: %.2f is out of the velocity range' % (minVel)) |
|
819 | print('minVel: %.2f is out of the velocity range' % (minVel)) | |
824 | print('minVel is setting to %.2f' % (velrange[0])) |
|
820 | print('minVel is setting to %.2f' % (velrange[0])) | |
825 | minVel = velrange[0] |
|
821 | minVel = velrange[0] | |
826 |
|
822 | |||
827 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
823 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
828 | print('maxVel: %.2f is out of the velocity range' % (maxVel)) |
|
824 | print('maxVel: %.2f is out of the velocity range' % (maxVel)) | |
829 | print('maxVel is setting to %.2f' % (velrange[-1])) |
|
825 | print('maxVel is setting to %.2f' % (velrange[-1])) | |
830 | maxVel = velrange[-1] |
|
826 | maxVel = velrange[-1] | |
831 |
|
827 | |||
832 | # seleccion de indices para rango |
|
828 | # seleccion de indices para rango | |
833 | minIndex = 0 |
|
829 | minIndex = 0 | |
834 | maxIndex = 0 |
|
830 | maxIndex = 0 | |
835 | heights = self.dataOut.heightList |
|
831 | heights = self.dataOut.heightList | |
836 |
|
832 | |||
837 | inda = numpy.where(heights >= minHei) |
|
833 | inda = numpy.where(heights >= minHei) | |
838 | indb = numpy.where(heights <= maxHei) |
|
834 | indb = numpy.where(heights <= maxHei) | |
839 |
|
835 | |||
840 | try: |
|
836 | try: | |
841 | minIndex = inda[0][0] |
|
837 | minIndex = inda[0][0] | |
842 | except: |
|
838 | except: | |
843 | minIndex = 0 |
|
839 | minIndex = 0 | |
844 |
|
840 | |||
845 | try: |
|
841 | try: | |
846 | maxIndex = indb[0][-1] |
|
842 | maxIndex = indb[0][-1] | |
847 | except: |
|
843 | except: | |
848 | maxIndex = len(heights) |
|
844 | maxIndex = len(heights) | |
849 |
|
845 | |||
850 | if (minIndex < 0) or (minIndex > maxIndex): |
|
846 | if (minIndex < 0) or (minIndex > maxIndex): | |
851 | raise ValueError("some value in (%d,%d) is not valid" % ( |
|
847 | raise ValueError("some value in (%d,%d) is not valid" % ( | |
852 | minIndex, maxIndex)) |
|
848 | minIndex, maxIndex)) | |
853 |
|
849 | |||
854 | if (maxIndex >= self.dataOut.nHeights): |
|
850 | if (maxIndex >= self.dataOut.nHeights): | |
855 | maxIndex = self.dataOut.nHeights - 1 |
|
851 | maxIndex = self.dataOut.nHeights - 1 | |
856 |
|
852 | |||
857 | # seleccion de indices para velocidades |
|
853 | # seleccion de indices para velocidades | |
858 | indminvel = numpy.where(velrange >= minVel) |
|
854 | indminvel = numpy.where(velrange >= minVel) | |
859 | indmaxvel = numpy.where(velrange <= maxVel) |
|
855 | indmaxvel = numpy.where(velrange <= maxVel) | |
860 | try: |
|
856 | try: | |
861 | minIndexVel = indminvel[0][0] |
|
857 | minIndexVel = indminvel[0][0] | |
862 | except: |
|
858 | except: | |
863 | minIndexVel = 0 |
|
859 | minIndexVel = 0 | |
864 |
|
860 | |||
865 | try: |
|
861 | try: | |
866 | maxIndexVel = indmaxvel[0][-1] |
|
862 | maxIndexVel = indmaxvel[0][-1] | |
867 | except: |
|
863 | except: | |
868 | maxIndexVel = len(velrange) |
|
864 | maxIndexVel = len(velrange) | |
869 |
|
865 | |||
870 | # seleccion del espectro |
|
866 | # seleccion del espectro | |
871 | data_spc = self.dataOut.data_spc[:, |
|
867 | data_spc = self.dataOut.data_spc[:, | |
872 | minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] |
|
868 | minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] | |
873 | # estimacion de ruido |
|
869 | # estimacion de ruido | |
874 | noise = numpy.zeros(self.dataOut.nChannels) |
|
870 | noise = numpy.zeros(self.dataOut.nChannels) | |
875 |
|
871 | |||
876 | for channel in range(self.dataOut.nChannels): |
|
872 | for channel in range(self.dataOut.nChannels): | |
877 | daux = data_spc[channel, :, :] |
|
873 | daux = data_spc[channel, :, :] | |
878 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
874 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |
879 |
|
875 | |||
880 | self.dataOut.noise_estimation = noise.copy() |
|
876 | self.dataOut.noise_estimation = noise.copy() | |
881 |
|
877 | |||
882 | return 1 |
|
878 | return 1 | |
883 |
|
879 | |||
884 |
|
880 | |||
885 | class IncohInt(Operation): |
|
881 | class IncohInt(Operation): | |
886 |
|
882 | |||
887 | __profIndex = 0 |
|
883 | __profIndex = 0 | |
888 | __withOverapping = False |
|
884 | __withOverapping = False | |
889 |
|
885 | |||
890 | __byTime = False |
|
886 | __byTime = False | |
891 | __initime = None |
|
887 | __initime = None | |
892 | __lastdatatime = None |
|
888 | __lastdatatime = None | |
893 | __integrationtime = None |
|
889 | __integrationtime = None | |
894 |
|
890 | |||
895 | __buffer_spc = None |
|
891 | __buffer_spc = None | |
896 | __buffer_cspc = None |
|
892 | __buffer_cspc = None | |
897 | __buffer_dc = None |
|
893 | __buffer_dc = None | |
898 |
|
894 | |||
899 | __dataReady = False |
|
895 | __dataReady = False | |
900 |
|
896 | |||
901 | __timeInterval = None |
|
897 | __timeInterval = None | |
902 |
|
898 | |||
903 | n = None |
|
899 | n = None | |
904 |
|
900 | |||
905 | def __init__(self): |
|
901 | def __init__(self): | |
906 |
|
902 | |||
907 | Operation.__init__(self) |
|
903 | Operation.__init__(self) | |
908 |
|
904 | |||
909 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
905 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
910 | """ |
|
906 | """ | |
911 | Set the parameters of the integration class. |
|
907 | Set the parameters of the integration class. | |
912 |
|
908 | |||
913 | Inputs: |
|
909 | Inputs: | |
914 |
|
910 | |||
915 | n : Number of coherent integrations |
|
911 | n : Number of coherent integrations | |
916 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
912 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
917 | overlapping : |
|
913 | overlapping : | |
918 |
|
914 | |||
919 | """ |
|
915 | """ | |
920 |
|
916 | |||
921 | self.__initime = None |
|
917 | self.__initime = None | |
922 | self.__lastdatatime = 0 |
|
918 | self.__lastdatatime = 0 | |
923 |
|
919 | |||
924 | self.__buffer_spc = 0 |
|
920 | self.__buffer_spc = 0 | |
925 | self.__buffer_cspc = 0 |
|
921 | self.__buffer_cspc = 0 | |
926 | self.__buffer_dc = 0 |
|
922 | self.__buffer_dc = 0 | |
927 |
|
923 | |||
928 | self.__profIndex = 0 |
|
924 | self.__profIndex = 0 | |
929 | self.__dataReady = False |
|
925 | self.__dataReady = False | |
930 | self.__byTime = False |
|
926 | self.__byTime = False | |
931 |
|
927 | |||
932 | if n is None and timeInterval is None: |
|
928 | if n is None and timeInterval is None: | |
933 | raise ValueError("n or timeInterval should be specified ...") |
|
929 | raise ValueError("n or timeInterval should be specified ...") | |
934 |
|
930 | |||
935 | if n is not None: |
|
931 | if n is not None: | |
936 | self.n = int(n) |
|
932 | self.n = int(n) | |
937 | else: |
|
933 | else: | |
938 |
|
934 | |||
939 | self.__integrationtime = int(timeInterval) |
|
935 | self.__integrationtime = int(timeInterval) | |
940 | self.n = None |
|
936 | self.n = None | |
941 | self.__byTime = True |
|
937 | self.__byTime = True | |
942 |
|
938 | |||
943 | def putData(self, data_spc, data_cspc, data_dc): |
|
939 | def putData(self, data_spc, data_cspc, data_dc): | |
944 | """ |
|
940 | """ | |
945 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
941 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
946 |
|
942 | |||
947 | """ |
|
943 | """ | |
948 |
|
944 | |||
949 | self.__buffer_spc += data_spc |
|
945 | self.__buffer_spc += data_spc | |
950 |
|
946 | |||
951 | if data_cspc is None: |
|
947 | if data_cspc is None: | |
952 | self.__buffer_cspc = None |
|
948 | self.__buffer_cspc = None | |
953 | else: |
|
949 | else: | |
954 | self.__buffer_cspc += data_cspc |
|
950 | self.__buffer_cspc += data_cspc | |
955 |
|
951 | |||
956 | if data_dc is None: |
|
952 | if data_dc is None: | |
957 | self.__buffer_dc = None |
|
953 | self.__buffer_dc = None | |
958 | else: |
|
954 | else: | |
959 | self.__buffer_dc += data_dc |
|
955 | self.__buffer_dc += data_dc | |
960 |
|
956 | |||
961 | self.__profIndex += 1 |
|
957 | self.__profIndex += 1 | |
962 |
|
958 | |||
963 | return |
|
959 | return | |
964 |
|
960 | |||
965 | def pushData(self): |
|
961 | def pushData(self): | |
966 | """ |
|
962 | """ | |
967 | Return the sum of the last profiles and the profiles used in the sum. |
|
963 | Return the sum of the last profiles and the profiles used in the sum. | |
968 |
|
964 | |||
969 | Affected: |
|
965 | Affected: | |
970 |
|
966 | |||
971 | self.__profileIndex |
|
967 | self.__profileIndex | |
972 |
|
968 | |||
973 | """ |
|
969 | """ | |
974 |
|
970 | |||
975 | data_spc = self.__buffer_spc |
|
971 | data_spc = self.__buffer_spc | |
976 | data_cspc = self.__buffer_cspc |
|
972 | data_cspc = self.__buffer_cspc | |
977 | data_dc = self.__buffer_dc |
|
973 | data_dc = self.__buffer_dc | |
978 | n = self.__profIndex |
|
974 | n = self.__profIndex | |
979 |
|
975 | |||
980 | self.__buffer_spc = 0 |
|
976 | self.__buffer_spc = 0 | |
981 | self.__buffer_cspc = 0 |
|
977 | self.__buffer_cspc = 0 | |
982 | self.__buffer_dc = 0 |
|
978 | self.__buffer_dc = 0 | |
983 | self.__profIndex = 0 |
|
979 | self.__profIndex = 0 | |
984 |
|
980 | |||
985 | return data_spc, data_cspc, data_dc, n |
|
981 | return data_spc, data_cspc, data_dc, n | |
986 |
|
982 | |||
987 | def byProfiles(self, *args): |
|
983 | def byProfiles(self, *args): | |
988 |
|
984 | |||
989 | self.__dataReady = False |
|
985 | self.__dataReady = False | |
990 | avgdata_spc = None |
|
986 | avgdata_spc = None | |
991 | avgdata_cspc = None |
|
987 | avgdata_cspc = None | |
992 | avgdata_dc = None |
|
988 | avgdata_dc = None | |
993 |
|
989 | |||
994 | self.putData(*args) |
|
990 | self.putData(*args) | |
995 |
|
991 | |||
996 | if self.__profIndex == self.n: |
|
992 | if self.__profIndex == self.n: | |
997 |
|
993 | |||
998 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
994 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
999 | self.n = n |
|
995 | self.n = n | |
1000 | self.__dataReady = True |
|
996 | self.__dataReady = True | |
1001 |
|
997 | |||
1002 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
998 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1003 |
|
999 | |||
1004 | def byTime(self, datatime, *args): |
|
1000 | def byTime(self, datatime, *args): | |
1005 |
|
1001 | |||
1006 | self.__dataReady = False |
|
1002 | self.__dataReady = False | |
1007 | avgdata_spc = None |
|
1003 | avgdata_spc = None | |
1008 | avgdata_cspc = None |
|
1004 | avgdata_cspc = None | |
1009 | avgdata_dc = None |
|
1005 | avgdata_dc = None | |
1010 |
|
1006 | |||
1011 | self.putData(*args) |
|
1007 | self.putData(*args) | |
1012 |
|
1008 | |||
1013 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1009 | if (datatime - self.__initime) >= self.__integrationtime: | |
1014 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1010 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1015 | self.n = n |
|
1011 | self.n = n | |
1016 | self.__dataReady = True |
|
1012 | self.__dataReady = True | |
1017 |
|
1013 | |||
1018 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1014 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1019 |
|
1015 | |||
1020 | def integrate(self, datatime, *args): |
|
1016 | def integrate(self, datatime, *args): | |
1021 |
|
1017 | |||
1022 | if self.__profIndex == 0: |
|
1018 | if self.__profIndex == 0: | |
1023 | self.__initime = datatime |
|
1019 | self.__initime = datatime | |
1024 |
|
1020 | |||
1025 | if self.__byTime: |
|
1021 | if self.__byTime: | |
1026 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( |
|
1022 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( | |
1027 | datatime, *args) |
|
1023 | datatime, *args) | |
1028 | else: |
|
1024 | else: | |
1029 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1025 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
1030 |
|
1026 | |||
1031 | if not self.__dataReady: |
|
1027 | if not self.__dataReady: | |
1032 | return None, None, None, None |
|
1028 | return None, None, None, None | |
1033 |
|
1029 | |||
1034 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1030 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc | |
1035 |
|
1031 | |||
1036 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1032 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
1037 | if n == 1: |
|
1033 | if n == 1: | |
1038 | return |
|
1034 | return | |
1039 |
|
1035 | |||
1040 | dataOut.flagNoData = True |
|
1036 | dataOut.flagNoData = True | |
1041 |
|
1037 | |||
1042 | if not self.isConfig: |
|
1038 | if not self.isConfig: | |
1043 | self.setup(n, timeInterval, overlapping) |
|
1039 | self.setup(n, timeInterval, overlapping) | |
1044 | self.isConfig = True |
|
1040 | self.isConfig = True | |
1045 |
|
1041 | |||
1046 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1042 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
1047 | dataOut.data_spc, |
|
1043 | dataOut.data_spc, | |
1048 | dataOut.data_cspc, |
|
1044 | dataOut.data_cspc, | |
1049 | dataOut.data_dc) |
|
1045 | dataOut.data_dc) | |
1050 |
|
1046 | |||
1051 | if self.__dataReady: |
|
1047 | if self.__dataReady: | |
1052 |
|
1048 | |||
1053 | dataOut.data_spc = avgdata_spc |
|
1049 | dataOut.data_spc = avgdata_spc | |
1054 | dataOut.data_cspc = avgdata_cspc |
|
1050 | dataOut.data_cspc = avgdata_cspc | |
1055 | dataOut.data_dc = avgdata_dc |
|
1051 | dataOut.data_dc = avgdata_dc | |
1056 | dataOut.nIncohInt *= self.n |
|
1052 | dataOut.nIncohInt *= self.n | |
1057 | dataOut.utctime = avgdatatime |
|
1053 | dataOut.utctime = avgdatatime | |
1058 | dataOut.flagNoData = False |
|
1054 | dataOut.flagNoData = False | |
1059 |
|
1055 | |||
1060 | return dataOut No newline at end of file |
|
1056 | return dataOut |
@@ -1,1329 +1,1329 | |||||
1 | import sys |
|
1 | import sys | |
2 | import numpy |
|
2 | import numpy | |
3 | from scipy import interpolate |
|
3 | from scipy import interpolate | |
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
4 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
5 | from schainpy.model.data.jrodata import Voltage |
|
5 | from schainpy.model.data.jrodata import Voltage | |
6 | from schainpy.utils import log |
|
6 | from schainpy.utils import log | |
7 | from time import time |
|
7 | from time import time | |
8 |
|
8 | |||
9 |
|
9 | |||
10 | @MPDecorator |
|
10 | @MPDecorator | |
11 | class VoltageProc(ProcessingUnit): |
|
11 | class VoltageProc(ProcessingUnit): | |
12 |
|
12 | |||
13 | def __init__(self): |
|
13 | def __init__(self): | |
14 |
|
14 | |||
15 | ProcessingUnit.__init__(self) |
|
15 | ProcessingUnit.__init__(self) | |
16 |
|
16 | |||
17 | self.dataOut = Voltage() |
|
17 | self.dataOut = Voltage() | |
18 | self.flip = 1 |
|
18 | self.flip = 1 | |
19 | self.setupReq = False |
|
19 | self.setupReq = False | |
20 |
|
20 | |||
21 | def run(self): |
|
21 | def run(self): | |
22 |
|
22 | |||
23 | if self.dataIn.type == 'AMISR': |
|
23 | if self.dataIn.type == 'AMISR': | |
24 | self.__updateObjFromAmisrInput() |
|
24 | self.__updateObjFromAmisrInput() | |
25 |
|
25 | |||
26 | if self.dataIn.type == 'Voltage': |
|
26 | if self.dataIn.type == 'Voltage': | |
27 | self.dataOut.copy(self.dataIn) |
|
27 | self.dataOut.copy(self.dataIn) | |
28 |
|
28 | |||
29 | # self.dataOut.copy(self.dataIn) |
|
29 | # self.dataOut.copy(self.dataIn) | |
30 |
|
30 | |||
31 | def __updateObjFromAmisrInput(self): |
|
31 | def __updateObjFromAmisrInput(self): | |
32 |
|
32 | |||
33 | self.dataOut.timeZone = self.dataIn.timeZone |
|
33 | self.dataOut.timeZone = self.dataIn.timeZone | |
34 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
34 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
35 | self.dataOut.errorCount = self.dataIn.errorCount |
|
35 | self.dataOut.errorCount = self.dataIn.errorCount | |
36 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
36 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
37 |
|
37 | |||
38 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
38 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
39 | self.dataOut.data = self.dataIn.data |
|
39 | self.dataOut.data = self.dataIn.data | |
40 | self.dataOut.utctime = self.dataIn.utctime |
|
40 | self.dataOut.utctime = self.dataIn.utctime | |
41 | self.dataOut.channelList = self.dataIn.channelList |
|
41 | self.dataOut.channelList = self.dataIn.channelList | |
42 | #self.dataOut.timeInterval = self.dataIn.timeInterval |
|
42 | #self.dataOut.timeInterval = self.dataIn.timeInterval | |
43 | self.dataOut.heightList = self.dataIn.heightList |
|
43 | self.dataOut.heightList = self.dataIn.heightList | |
44 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
44 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
45 |
|
45 | |||
46 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
46 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
47 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
47 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
48 | self.dataOut.frequency = self.dataIn.frequency |
|
48 | self.dataOut.frequency = self.dataIn.frequency | |
49 |
|
49 | |||
50 | self.dataOut.azimuth = self.dataIn.azimuth |
|
50 | self.dataOut.azimuth = self.dataIn.azimuth | |
51 | self.dataOut.zenith = self.dataIn.zenith |
|
51 | self.dataOut.zenith = self.dataIn.zenith | |
52 |
|
52 | |||
53 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
53 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
54 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
54 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
55 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
55 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
56 | # |
|
56 | # | |
57 | # pass# |
|
57 | # pass# | |
58 | # |
|
58 | # | |
59 | # def init(self): |
|
59 | # def init(self): | |
60 | # |
|
60 | # | |
61 | # |
|
61 | # | |
62 | # if self.dataIn.type == 'AMISR': |
|
62 | # if self.dataIn.type == 'AMISR': | |
63 | # self.__updateObjFromAmisrInput() |
|
63 | # self.__updateObjFromAmisrInput() | |
64 | # |
|
64 | # | |
65 | # if self.dataIn.type == 'Voltage': |
|
65 | # if self.dataIn.type == 'Voltage': | |
66 | # self.dataOut.copy(self.dataIn) |
|
66 | # self.dataOut.copy(self.dataIn) | |
67 | # # No necesita copiar en cada init() los atributos de dataIn |
|
67 | # # No necesita copiar en cada init() los atributos de dataIn | |
68 | # # la copia deberia hacerse por cada nuevo bloque de datos |
|
68 | # # la copia deberia hacerse por cada nuevo bloque de datos | |
69 |
|
69 | |||
70 | def selectChannels(self, channelList): |
|
70 | def selectChannels(self, channelList): | |
71 |
|
71 | |||
72 | channelIndexList = [] |
|
72 | channelIndexList = [] | |
73 |
|
73 | |||
74 | for channel in channelList: |
|
74 | for channel in channelList: | |
75 | if channel not in self.dataOut.channelList: |
|
75 | if channel not in self.dataOut.channelList: | |
76 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) |
|
76 | raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList))) | |
77 |
|
77 | |||
78 | index = self.dataOut.channelList.index(channel) |
|
78 | index = self.dataOut.channelList.index(channel) | |
79 | channelIndexList.append(index) |
|
79 | channelIndexList.append(index) | |
80 |
|
80 | |||
81 | self.selectChannelsByIndex(channelIndexList) |
|
81 | self.selectChannelsByIndex(channelIndexList) | |
82 |
|
82 | |||
83 | def selectChannelsByIndex(self, channelIndexList): |
|
83 | def selectChannelsByIndex(self, channelIndexList): | |
84 | """ |
|
84 | """ | |
85 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
85 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
86 |
|
86 | |||
87 | Input: |
|
87 | Input: | |
88 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
88 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
89 |
|
89 | |||
90 | Affected: |
|
90 | Affected: | |
91 | self.dataOut.data |
|
91 | self.dataOut.data | |
92 | self.dataOut.channelIndexList |
|
92 | self.dataOut.channelIndexList | |
93 | self.dataOut.nChannels |
|
93 | self.dataOut.nChannels | |
94 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
94 | self.dataOut.m_ProcessingHeader.totalSpectra | |
95 | self.dataOut.systemHeaderObj.numChannels |
|
95 | self.dataOut.systemHeaderObj.numChannels | |
96 | self.dataOut.m_ProcessingHeader.blockSize |
|
96 | self.dataOut.m_ProcessingHeader.blockSize | |
97 |
|
97 | |||
98 | Return: |
|
98 | Return: | |
99 | None |
|
99 | None | |
100 | """ |
|
100 | """ | |
101 |
|
101 | |||
102 | for channelIndex in channelIndexList: |
|
102 | for channelIndex in channelIndexList: | |
103 | if channelIndex not in self.dataOut.channelIndexList: |
|
103 | if channelIndex not in self.dataOut.channelIndexList: | |
104 | print(channelIndexList) |
|
104 | print(channelIndexList) | |
105 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) |
|
105 | raise ValueError("The value %d in channelIndexList is not valid" %channelIndex) | |
106 |
|
106 | |||
107 | if self.dataOut.flagDataAsBlock: |
|
107 | if self.dataOut.flagDataAsBlock: | |
108 | """ |
|
108 | """ | |
109 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
109 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
110 | """ |
|
110 | """ | |
111 | data = self.dataOut.data[channelIndexList,:,:] |
|
111 | data = self.dataOut.data[channelIndexList,:,:] | |
112 | else: |
|
112 | else: | |
113 | data = self.dataOut.data[channelIndexList,:] |
|
113 | data = self.dataOut.data[channelIndexList,:] | |
114 |
|
114 | |||
115 | self.dataOut.data = data |
|
115 | self.dataOut.data = data | |
116 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
116 | # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
117 |
|
|
117 | self.dataOut.channelList = range(len(channelIndexList)) | |
118 |
|
118 | |||
119 | return 1 |
|
119 | return 1 | |
120 |
|
120 | |||
121 | def selectHeights(self, minHei=None, maxHei=None): |
|
121 | def selectHeights(self, minHei=None, maxHei=None): | |
122 | """ |
|
122 | """ | |
123 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
123 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
124 | minHei <= height <= maxHei |
|
124 | minHei <= height <= maxHei | |
125 |
|
125 | |||
126 | Input: |
|
126 | Input: | |
127 | minHei : valor minimo de altura a considerar |
|
127 | minHei : valor minimo de altura a considerar | |
128 | maxHei : valor maximo de altura a considerar |
|
128 | maxHei : valor maximo de altura a considerar | |
129 |
|
129 | |||
130 | Affected: |
|
130 | Affected: | |
131 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
131 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
132 |
|
132 | |||
133 | Return: |
|
133 | Return: | |
134 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
134 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
135 | """ |
|
135 | """ | |
136 |
|
136 | |||
137 | if minHei == None: |
|
137 | if minHei == None: | |
138 | minHei = self.dataOut.heightList[0] |
|
138 | minHei = self.dataOut.heightList[0] | |
139 |
|
139 | |||
140 | if maxHei == None: |
|
140 | if maxHei == None: | |
141 | maxHei = self.dataOut.heightList[-1] |
|
141 | maxHei = self.dataOut.heightList[-1] | |
142 |
|
142 | |||
143 | if (minHei < self.dataOut.heightList[0]): |
|
143 | if (minHei < self.dataOut.heightList[0]): | |
144 | minHei = self.dataOut.heightList[0] |
|
144 | minHei = self.dataOut.heightList[0] | |
145 |
|
145 | |||
146 | if (maxHei > self.dataOut.heightList[-1]): |
|
146 | if (maxHei > self.dataOut.heightList[-1]): | |
147 | maxHei = self.dataOut.heightList[-1] |
|
147 | maxHei = self.dataOut.heightList[-1] | |
148 |
|
148 | |||
149 | minIndex = 0 |
|
149 | minIndex = 0 | |
150 | maxIndex = 0 |
|
150 | maxIndex = 0 | |
151 | heights = self.dataOut.heightList |
|
151 | heights = self.dataOut.heightList | |
152 |
|
152 | |||
153 | inda = numpy.where(heights >= minHei) |
|
153 | inda = numpy.where(heights >= minHei) | |
154 | indb = numpy.where(heights <= maxHei) |
|
154 | indb = numpy.where(heights <= maxHei) | |
155 |
|
155 | |||
156 | try: |
|
156 | try: | |
157 | minIndex = inda[0][0] |
|
157 | minIndex = inda[0][0] | |
158 | except: |
|
158 | except: | |
159 | minIndex = 0 |
|
159 | minIndex = 0 | |
160 |
|
160 | |||
161 | try: |
|
161 | try: | |
162 | maxIndex = indb[0][-1] |
|
162 | maxIndex = indb[0][-1] | |
163 | except: |
|
163 | except: | |
164 | maxIndex = len(heights) |
|
164 | maxIndex = len(heights) | |
165 |
|
165 | |||
166 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
166 | self.selectHeightsByIndex(minIndex, maxIndex) | |
167 |
|
167 | |||
168 | return 1 |
|
168 | return 1 | |
169 |
|
169 | |||
170 |
|
170 | |||
171 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
171 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
172 | """ |
|
172 | """ | |
173 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
173 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
174 | minIndex <= index <= maxIndex |
|
174 | minIndex <= index <= maxIndex | |
175 |
|
175 | |||
176 | Input: |
|
176 | Input: | |
177 | minIndex : valor de indice minimo de altura a considerar |
|
177 | minIndex : valor de indice minimo de altura a considerar | |
178 | maxIndex : valor de indice maximo de altura a considerar |
|
178 | maxIndex : valor de indice maximo de altura a considerar | |
179 |
|
179 | |||
180 | Affected: |
|
180 | Affected: | |
181 | self.dataOut.data |
|
181 | self.dataOut.data | |
182 | self.dataOut.heightList |
|
182 | self.dataOut.heightList | |
183 |
|
183 | |||
184 | Return: |
|
184 | Return: | |
185 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
185 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
186 | """ |
|
186 | """ | |
187 |
|
187 | |||
188 | if (minIndex < 0) or (minIndex > maxIndex): |
|
188 | if (minIndex < 0) or (minIndex > maxIndex): | |
189 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
189 | raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
190 |
|
190 | |||
191 | if (maxIndex >= self.dataOut.nHeights): |
|
191 | if (maxIndex >= self.dataOut.nHeights): | |
192 | maxIndex = self.dataOut.nHeights |
|
192 | maxIndex = self.dataOut.nHeights | |
193 |
|
193 | |||
194 | #voltage |
|
194 | #voltage | |
195 | if self.dataOut.flagDataAsBlock: |
|
195 | if self.dataOut.flagDataAsBlock: | |
196 | """ |
|
196 | """ | |
197 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
197 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
198 | """ |
|
198 | """ | |
199 | data = self.dataOut.data[:,:, minIndex:maxIndex] |
|
199 | data = self.dataOut.data[:,:, minIndex:maxIndex] | |
200 | else: |
|
200 | else: | |
201 | data = self.dataOut.data[:, minIndex:maxIndex] |
|
201 | data = self.dataOut.data[:, minIndex:maxIndex] | |
202 |
|
202 | |||
203 | # firstHeight = self.dataOut.heightList[minIndex] |
|
203 | # firstHeight = self.dataOut.heightList[minIndex] | |
204 |
|
204 | |||
205 | self.dataOut.data = data |
|
205 | self.dataOut.data = data | |
206 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] |
|
206 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex] | |
207 |
|
207 | |||
208 | if self.dataOut.nHeights <= 1: |
|
208 | if self.dataOut.nHeights <= 1: | |
209 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) |
|
209 | raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)) | |
210 |
|
210 | |||
211 | return 1 |
|
211 | return 1 | |
212 |
|
212 | |||
213 |
|
213 | |||
214 | def filterByHeights(self, window): |
|
214 | def filterByHeights(self, window): | |
215 |
|
215 | |||
216 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
216 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
217 |
|
217 | |||
218 | if window == None: |
|
218 | if window == None: | |
219 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
219 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
220 |
|
220 | |||
221 | newdelta = deltaHeight * window |
|
221 | newdelta = deltaHeight * window | |
222 | r = self.dataOut.nHeights % window |
|
222 | r = self.dataOut.nHeights % window | |
223 | newheights = (self.dataOut.nHeights-r)/window |
|
223 | newheights = (self.dataOut.nHeights-r)/window | |
224 |
|
224 | |||
225 | if newheights <= 1: |
|
225 | if newheights <= 1: | |
226 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)) |
|
226 | raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)) | |
227 |
|
227 | |||
228 | if self.dataOut.flagDataAsBlock: |
|
228 | if self.dataOut.flagDataAsBlock: | |
229 | """ |
|
229 | """ | |
230 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
230 | Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
231 | """ |
|
231 | """ | |
232 | buffer = self.dataOut.data[:, :, 0:int(self.dataOut.nHeights-r)] |
|
232 | buffer = self.dataOut.data[:, :, 0:int(self.dataOut.nHeights-r)] | |
233 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) |
|
233 | buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window) | |
234 | buffer = numpy.sum(buffer,3) |
|
234 | buffer = numpy.sum(buffer,3) | |
235 |
|
235 | |||
236 | else: |
|
236 | else: | |
237 | buffer = self.dataOut.data[:,0:int(self.dataOut.nHeights-r)] |
|
237 | buffer = self.dataOut.data[:,0:int(self.dataOut.nHeights-r)] | |
238 | buffer = buffer.reshape(self.dataOut.nChannels,int(self.dataOut.nHeights/window),int(window)) |
|
238 | buffer = buffer.reshape(self.dataOut.nChannels,int(self.dataOut.nHeights/window),int(window)) | |
239 | buffer = numpy.sum(buffer,2) |
|
239 | buffer = numpy.sum(buffer,2) | |
240 |
|
240 | |||
241 | self.dataOut.data = buffer |
|
241 | self.dataOut.data = buffer | |
242 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta |
|
242 | self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta | |
243 | self.dataOut.windowOfFilter = window |
|
243 | self.dataOut.windowOfFilter = window | |
244 |
|
244 | |||
245 | def setH0(self, h0, deltaHeight = None): |
|
245 | def setH0(self, h0, deltaHeight = None): | |
246 |
|
246 | |||
247 | if not deltaHeight: |
|
247 | if not deltaHeight: | |
248 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
248 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
249 |
|
249 | |||
250 | nHeights = self.dataOut.nHeights |
|
250 | nHeights = self.dataOut.nHeights | |
251 |
|
251 | |||
252 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
252 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
253 |
|
253 | |||
254 | self.dataOut.heightList = newHeiRange |
|
254 | self.dataOut.heightList = newHeiRange | |
255 |
|
255 | |||
256 | def deFlip(self, channelList = []): |
|
256 | def deFlip(self, channelList = []): | |
257 |
|
257 | |||
258 | data = self.dataOut.data.copy() |
|
258 | data = self.dataOut.data.copy() | |
259 |
|
259 | |||
260 | if self.dataOut.flagDataAsBlock: |
|
260 | if self.dataOut.flagDataAsBlock: | |
261 | flip = self.flip |
|
261 | flip = self.flip | |
262 | profileList = list(range(self.dataOut.nProfiles)) |
|
262 | profileList = list(range(self.dataOut.nProfiles)) | |
263 |
|
263 | |||
264 | if not channelList: |
|
264 | if not channelList: | |
265 | for thisProfile in profileList: |
|
265 | for thisProfile in profileList: | |
266 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip |
|
266 | data[:,thisProfile,:] = data[:,thisProfile,:]*flip | |
267 | flip *= -1.0 |
|
267 | flip *= -1.0 | |
268 | else: |
|
268 | else: | |
269 | for thisChannel in channelList: |
|
269 | for thisChannel in channelList: | |
270 | if thisChannel not in self.dataOut.channelList: |
|
270 | if thisChannel not in self.dataOut.channelList: | |
271 | continue |
|
271 | continue | |
272 |
|
272 | |||
273 | for thisProfile in profileList: |
|
273 | for thisProfile in profileList: | |
274 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip |
|
274 | data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip | |
275 | flip *= -1.0 |
|
275 | flip *= -1.0 | |
276 |
|
276 | |||
277 | self.flip = flip |
|
277 | self.flip = flip | |
278 |
|
278 | |||
279 | else: |
|
279 | else: | |
280 | if not channelList: |
|
280 | if not channelList: | |
281 | data[:,:] = data[:,:]*self.flip |
|
281 | data[:,:] = data[:,:]*self.flip | |
282 | else: |
|
282 | else: | |
283 | for thisChannel in channelList: |
|
283 | for thisChannel in channelList: | |
284 | if thisChannel not in self.dataOut.channelList: |
|
284 | if thisChannel not in self.dataOut.channelList: | |
285 | continue |
|
285 | continue | |
286 |
|
286 | |||
287 | data[thisChannel,:] = data[thisChannel,:]*self.flip |
|
287 | data[thisChannel,:] = data[thisChannel,:]*self.flip | |
288 |
|
288 | |||
289 | self.flip *= -1. |
|
289 | self.flip *= -1. | |
290 |
|
290 | |||
291 | self.dataOut.data = data |
|
291 | self.dataOut.data = data | |
292 |
|
292 | |||
293 | def setRadarFrequency(self, frequency=None): |
|
293 | def setRadarFrequency(self, frequency=None): | |
294 |
|
294 | |||
295 | if frequency != None: |
|
295 | if frequency != None: | |
296 | self.dataOut.frequency = frequency |
|
296 | self.dataOut.frequency = frequency | |
297 |
|
297 | |||
298 | return 1 |
|
298 | return 1 | |
299 |
|
299 | |||
300 | def interpolateHeights(self, topLim, botLim): |
|
300 | def interpolateHeights(self, topLim, botLim): | |
301 | #69 al 72 para julia |
|
301 | #69 al 72 para julia | |
302 | #82-84 para meteoros |
|
302 | #82-84 para meteoros | |
303 | if len(numpy.shape(self.dataOut.data))==2: |
|
303 | if len(numpy.shape(self.dataOut.data))==2: | |
304 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 |
|
304 | sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2 | |
305 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) |
|
305 | sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1))) | |
306 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp |
|
306 | #self.dataOut.data[:,botLim:limSup+1] = sampInterp | |
307 | self.dataOut.data[:,botLim:topLim+1] = sampInterp |
|
307 | self.dataOut.data[:,botLim:topLim+1] = sampInterp | |
308 | else: |
|
308 | else: | |
309 | nHeights = self.dataOut.data.shape[2] |
|
309 | nHeights = self.dataOut.data.shape[2] | |
310 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) |
|
310 | x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights))) | |
311 | y = self.dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] |
|
311 | y = self.dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))] | |
312 | f = interpolate.interp1d(x, y, axis = 2) |
|
312 | f = interpolate.interp1d(x, y, axis = 2) | |
313 | xnew = numpy.arange(botLim,topLim+1) |
|
313 | xnew = numpy.arange(botLim,topLim+1) | |
314 | ynew = f(xnew) |
|
314 | ynew = f(xnew) | |
315 |
|
315 | |||
316 | self.dataOut.data[:,:,botLim:topLim+1] = ynew |
|
316 | self.dataOut.data[:,:,botLim:topLim+1] = ynew | |
317 |
|
317 | |||
318 | # import collections |
|
318 | # import collections | |
319 |
|
319 | |||
320 | class CohInt(Operation): |
|
320 | class CohInt(Operation): | |
321 |
|
321 | |||
322 | isConfig = False |
|
322 | isConfig = False | |
323 | __profIndex = 0 |
|
323 | __profIndex = 0 | |
324 | __byTime = False |
|
324 | __byTime = False | |
325 | __initime = None |
|
325 | __initime = None | |
326 | __lastdatatime = None |
|
326 | __lastdatatime = None | |
327 | __integrationtime = None |
|
327 | __integrationtime = None | |
328 | __buffer = None |
|
328 | __buffer = None | |
329 | __bufferStride = [] |
|
329 | __bufferStride = [] | |
330 | __dataReady = False |
|
330 | __dataReady = False | |
331 | __profIndexStride = 0 |
|
331 | __profIndexStride = 0 | |
332 | __dataToPutStride = False |
|
332 | __dataToPutStride = False | |
333 | n = None |
|
333 | n = None | |
334 |
|
334 | |||
335 | def __init__(self, **kwargs): |
|
335 | def __init__(self, **kwargs): | |
336 |
|
336 | |||
337 | Operation.__init__(self, **kwargs) |
|
337 | Operation.__init__(self, **kwargs) | |
338 |
|
338 | |||
339 | # self.isConfig = False |
|
339 | # self.isConfig = False | |
340 |
|
340 | |||
341 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): |
|
341 | def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False): | |
342 | """ |
|
342 | """ | |
343 | Set the parameters of the integration class. |
|
343 | Set the parameters of the integration class. | |
344 |
|
344 | |||
345 | Inputs: |
|
345 | Inputs: | |
346 |
|
346 | |||
347 | n : Number of coherent integrations |
|
347 | n : Number of coherent integrations | |
348 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
348 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
349 | overlapping : |
|
349 | overlapping : | |
350 | """ |
|
350 | """ | |
351 |
|
351 | |||
352 | self.__initime = None |
|
352 | self.__initime = None | |
353 | self.__lastdatatime = 0 |
|
353 | self.__lastdatatime = 0 | |
354 | self.__buffer = None |
|
354 | self.__buffer = None | |
355 | self.__dataReady = False |
|
355 | self.__dataReady = False | |
356 | self.byblock = byblock |
|
356 | self.byblock = byblock | |
357 | self.stride = stride |
|
357 | self.stride = stride | |
358 |
|
358 | |||
359 | if n == None and timeInterval == None: |
|
359 | if n == None and timeInterval == None: | |
360 | raise ValueError("n or timeInterval should be specified ...") |
|
360 | raise ValueError("n or timeInterval should be specified ...") | |
361 |
|
361 | |||
362 | if n != None: |
|
362 | if n != None: | |
363 | self.n = n |
|
363 | self.n = n | |
364 | self.__byTime = False |
|
364 | self.__byTime = False | |
365 | else: |
|
365 | else: | |
366 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
366 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
367 | self.n = 9999 |
|
367 | self.n = 9999 | |
368 | self.__byTime = True |
|
368 | self.__byTime = True | |
369 |
|
369 | |||
370 | if overlapping: |
|
370 | if overlapping: | |
371 | self.__withOverlapping = True |
|
371 | self.__withOverlapping = True | |
372 | self.__buffer = None |
|
372 | self.__buffer = None | |
373 | else: |
|
373 | else: | |
374 | self.__withOverlapping = False |
|
374 | self.__withOverlapping = False | |
375 | self.__buffer = 0 |
|
375 | self.__buffer = 0 | |
376 |
|
376 | |||
377 | self.__profIndex = 0 |
|
377 | self.__profIndex = 0 | |
378 |
|
378 | |||
379 | def putData(self, data): |
|
379 | def putData(self, data): | |
380 |
|
380 | |||
381 | """ |
|
381 | """ | |
382 | Add a profile to the __buffer and increase in one the __profileIndex |
|
382 | Add a profile to the __buffer and increase in one the __profileIndex | |
383 |
|
383 | |||
384 | """ |
|
384 | """ | |
385 |
|
385 | |||
386 | if not self.__withOverlapping: |
|
386 | if not self.__withOverlapping: | |
387 | self.__buffer += data.copy() |
|
387 | self.__buffer += data.copy() | |
388 | self.__profIndex += 1 |
|
388 | self.__profIndex += 1 | |
389 | return |
|
389 | return | |
390 |
|
390 | |||
391 | #Overlapping data |
|
391 | #Overlapping data | |
392 | nChannels, nHeis = data.shape |
|
392 | nChannels, nHeis = data.shape | |
393 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
393 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
394 |
|
394 | |||
395 | #If the buffer is empty then it takes the data value |
|
395 | #If the buffer is empty then it takes the data value | |
396 | if self.__buffer is None: |
|
396 | if self.__buffer is None: | |
397 | self.__buffer = data |
|
397 | self.__buffer = data | |
398 | self.__profIndex += 1 |
|
398 | self.__profIndex += 1 | |
399 | return |
|
399 | return | |
400 |
|
400 | |||
401 | #If the buffer length is lower than n then stakcing the data value |
|
401 | #If the buffer length is lower than n then stakcing the data value | |
402 | if self.__profIndex < self.n: |
|
402 | if self.__profIndex < self.n: | |
403 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
403 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
404 | self.__profIndex += 1 |
|
404 | self.__profIndex += 1 | |
405 | return |
|
405 | return | |
406 |
|
406 | |||
407 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
407 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
408 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
408 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
409 | self.__buffer[self.n-1] = data |
|
409 | self.__buffer[self.n-1] = data | |
410 | self.__profIndex = self.n |
|
410 | self.__profIndex = self.n | |
411 | return |
|
411 | return | |
412 |
|
412 | |||
413 |
|
413 | |||
414 | def pushData(self): |
|
414 | def pushData(self): | |
415 | """ |
|
415 | """ | |
416 | Return the sum of the last profiles and the profiles used in the sum. |
|
416 | Return the sum of the last profiles and the profiles used in the sum. | |
417 |
|
417 | |||
418 | Affected: |
|
418 | Affected: | |
419 |
|
419 | |||
420 | self.__profileIndex |
|
420 | self.__profileIndex | |
421 |
|
421 | |||
422 | """ |
|
422 | """ | |
423 |
|
423 | |||
424 | if not self.__withOverlapping: |
|
424 | if not self.__withOverlapping: | |
425 | data = self.__buffer |
|
425 | data = self.__buffer | |
426 | n = self.__profIndex |
|
426 | n = self.__profIndex | |
427 |
|
427 | |||
428 | self.__buffer = 0 |
|
428 | self.__buffer = 0 | |
429 | self.__profIndex = 0 |
|
429 | self.__profIndex = 0 | |
430 |
|
430 | |||
431 | return data, n |
|
431 | return data, n | |
432 |
|
432 | |||
433 | #Integration with Overlapping |
|
433 | #Integration with Overlapping | |
434 | data = numpy.sum(self.__buffer, axis=0) |
|
434 | data = numpy.sum(self.__buffer, axis=0) | |
435 | # print data |
|
435 | # print data | |
436 | # raise |
|
436 | # raise | |
437 | n = self.__profIndex |
|
437 | n = self.__profIndex | |
438 |
|
438 | |||
439 | return data, n |
|
439 | return data, n | |
440 |
|
440 | |||
441 | def byProfiles(self, data): |
|
441 | def byProfiles(self, data): | |
442 |
|
442 | |||
443 | self.__dataReady = False |
|
443 | self.__dataReady = False | |
444 | avgdata = None |
|
444 | avgdata = None | |
445 | # n = None |
|
445 | # n = None | |
446 | # print data |
|
446 | # print data | |
447 | # raise |
|
447 | # raise | |
448 | self.putData(data) |
|
448 | self.putData(data) | |
449 |
|
449 | |||
450 | if self.__profIndex == self.n: |
|
450 | if self.__profIndex == self.n: | |
451 | avgdata, n = self.pushData() |
|
451 | avgdata, n = self.pushData() | |
452 | self.__dataReady = True |
|
452 | self.__dataReady = True | |
453 |
|
453 | |||
454 | return avgdata |
|
454 | return avgdata | |
455 |
|
455 | |||
456 | def byTime(self, data, datatime): |
|
456 | def byTime(self, data, datatime): | |
457 |
|
457 | |||
458 | self.__dataReady = False |
|
458 | self.__dataReady = False | |
459 | avgdata = None |
|
459 | avgdata = None | |
460 | n = None |
|
460 | n = None | |
461 |
|
461 | |||
462 | self.putData(data) |
|
462 | self.putData(data) | |
463 |
|
463 | |||
464 | if (datatime - self.__initime) >= self.__integrationtime: |
|
464 | if (datatime - self.__initime) >= self.__integrationtime: | |
465 | avgdata, n = self.pushData() |
|
465 | avgdata, n = self.pushData() | |
466 | self.n = n |
|
466 | self.n = n | |
467 | self.__dataReady = True |
|
467 | self.__dataReady = True | |
468 |
|
468 | |||
469 | return avgdata |
|
469 | return avgdata | |
470 |
|
470 | |||
471 | def integrateByStride(self, data, datatime): |
|
471 | def integrateByStride(self, data, datatime): | |
472 | # print data |
|
472 | # print data | |
473 | if self.__profIndex == 0: |
|
473 | if self.__profIndex == 0: | |
474 | self.__buffer = [[data.copy(), datatime]] |
|
474 | self.__buffer = [[data.copy(), datatime]] | |
475 | else: |
|
475 | else: | |
476 | self.__buffer.append([data.copy(),datatime]) |
|
476 | self.__buffer.append([data.copy(),datatime]) | |
477 | self.__profIndex += 1 |
|
477 | self.__profIndex += 1 | |
478 | self.__dataReady = False |
|
478 | self.__dataReady = False | |
479 |
|
479 | |||
480 | if self.__profIndex == self.n * self.stride : |
|
480 | if self.__profIndex == self.n * self.stride : | |
481 | self.__dataToPutStride = True |
|
481 | self.__dataToPutStride = True | |
482 | self.__profIndexStride = 0 |
|
482 | self.__profIndexStride = 0 | |
483 | self.__profIndex = 0 |
|
483 | self.__profIndex = 0 | |
484 | self.__bufferStride = [] |
|
484 | self.__bufferStride = [] | |
485 | for i in range(self.stride): |
|
485 | for i in range(self.stride): | |
486 | current = self.__buffer[i::self.stride] |
|
486 | current = self.__buffer[i::self.stride] | |
487 | data = numpy.sum([t[0] for t in current], axis=0) |
|
487 | data = numpy.sum([t[0] for t in current], axis=0) | |
488 | avgdatatime = numpy.average([t[1] for t in current]) |
|
488 | avgdatatime = numpy.average([t[1] for t in current]) | |
489 | # print data |
|
489 | # print data | |
490 | self.__bufferStride.append((data, avgdatatime)) |
|
490 | self.__bufferStride.append((data, avgdatatime)) | |
491 |
|
491 | |||
492 | if self.__dataToPutStride: |
|
492 | if self.__dataToPutStride: | |
493 | self.__dataReady = True |
|
493 | self.__dataReady = True | |
494 | self.__profIndexStride += 1 |
|
494 | self.__profIndexStride += 1 | |
495 | if self.__profIndexStride == self.stride: |
|
495 | if self.__profIndexStride == self.stride: | |
496 | self.__dataToPutStride = False |
|
496 | self.__dataToPutStride = False | |
497 | # print self.__bufferStride[self.__profIndexStride - 1] |
|
497 | # print self.__bufferStride[self.__profIndexStride - 1] | |
498 | # raise |
|
498 | # raise | |
499 | return self.__bufferStride[self.__profIndexStride - 1] |
|
499 | return self.__bufferStride[self.__profIndexStride - 1] | |
500 |
|
500 | |||
501 |
|
501 | |||
502 | return None, None |
|
502 | return None, None | |
503 |
|
503 | |||
504 | def integrate(self, data, datatime=None): |
|
504 | def integrate(self, data, datatime=None): | |
505 |
|
505 | |||
506 | if self.__initime == None: |
|
506 | if self.__initime == None: | |
507 | self.__initime = datatime |
|
507 | self.__initime = datatime | |
508 |
|
508 | |||
509 | if self.__byTime: |
|
509 | if self.__byTime: | |
510 | avgdata = self.byTime(data, datatime) |
|
510 | avgdata = self.byTime(data, datatime) | |
511 | else: |
|
511 | else: | |
512 | avgdata = self.byProfiles(data) |
|
512 | avgdata = self.byProfiles(data) | |
513 |
|
513 | |||
514 |
|
514 | |||
515 | self.__lastdatatime = datatime |
|
515 | self.__lastdatatime = datatime | |
516 |
|
516 | |||
517 | if avgdata is None: |
|
517 | if avgdata is None: | |
518 | return None, None |
|
518 | return None, None | |
519 |
|
519 | |||
520 | avgdatatime = self.__initime |
|
520 | avgdatatime = self.__initime | |
521 |
|
521 | |||
522 | deltatime = datatime - self.__lastdatatime |
|
522 | deltatime = datatime - self.__lastdatatime | |
523 |
|
523 | |||
524 | if not self.__withOverlapping: |
|
524 | if not self.__withOverlapping: | |
525 | self.__initime = datatime |
|
525 | self.__initime = datatime | |
526 | else: |
|
526 | else: | |
527 | self.__initime += deltatime |
|
527 | self.__initime += deltatime | |
528 |
|
528 | |||
529 | return avgdata, avgdatatime |
|
529 | return avgdata, avgdatatime | |
530 |
|
530 | |||
531 | def integrateByBlock(self, dataOut): |
|
531 | def integrateByBlock(self, dataOut): | |
532 |
|
532 | |||
533 | times = int(dataOut.data.shape[1]/self.n) |
|
533 | times = int(dataOut.data.shape[1]/self.n) | |
534 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
534 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
535 |
|
535 | |||
536 | id_min = 0 |
|
536 | id_min = 0 | |
537 | id_max = self.n |
|
537 | id_max = self.n | |
538 |
|
538 | |||
539 | for i in range(times): |
|
539 | for i in range(times): | |
540 | junk = dataOut.data[:,id_min:id_max,:] |
|
540 | junk = dataOut.data[:,id_min:id_max,:] | |
541 | avgdata[:,i,:] = junk.sum(axis=1) |
|
541 | avgdata[:,i,:] = junk.sum(axis=1) | |
542 | id_min += self.n |
|
542 | id_min += self.n | |
543 | id_max += self.n |
|
543 | id_max += self.n | |
544 |
|
544 | |||
545 | timeInterval = dataOut.ippSeconds*self.n |
|
545 | timeInterval = dataOut.ippSeconds*self.n | |
546 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
546 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
547 | self.__dataReady = True |
|
547 | self.__dataReady = True | |
548 | return avgdata, avgdatatime |
|
548 | return avgdata, avgdatatime | |
549 |
|
549 | |||
550 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): |
|
550 | def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs): | |
551 |
|
551 | |||
552 | if not self.isConfig: |
|
552 | if not self.isConfig: | |
553 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) |
|
553 | self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs) | |
554 | self.isConfig = True |
|
554 | self.isConfig = True | |
555 |
|
555 | |||
556 | if dataOut.flagDataAsBlock: |
|
556 | if dataOut.flagDataAsBlock: | |
557 | """ |
|
557 | """ | |
558 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] |
|
558 | Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis] | |
559 | """ |
|
559 | """ | |
560 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
560 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
561 | dataOut.nProfiles /= self.n |
|
561 | dataOut.nProfiles /= self.n | |
562 | else: |
|
562 | else: | |
563 | if stride is None: |
|
563 | if stride is None: | |
564 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
564 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
565 | else: |
|
565 | else: | |
566 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) |
|
566 | avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime) | |
567 |
|
567 | |||
568 |
|
568 | |||
569 | # dataOut.timeInterval *= n |
|
569 | # dataOut.timeInterval *= n | |
570 | dataOut.flagNoData = True |
|
570 | dataOut.flagNoData = True | |
571 |
|
571 | |||
572 | if self.__dataReady: |
|
572 | if self.__dataReady: | |
573 | dataOut.data = avgdata |
|
573 | dataOut.data = avgdata | |
574 | dataOut.nCohInt *= self.n |
|
574 | dataOut.nCohInt *= self.n | |
575 | dataOut.utctime = avgdatatime |
|
575 | dataOut.utctime = avgdatatime | |
576 | # print avgdata, avgdatatime |
|
576 | # print avgdata, avgdatatime | |
577 | # raise |
|
577 | # raise | |
578 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
578 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
579 | dataOut.flagNoData = False |
|
579 | dataOut.flagNoData = False | |
580 | return dataOut |
|
580 | return dataOut | |
581 |
|
581 | |||
582 | class Decoder(Operation): |
|
582 | class Decoder(Operation): | |
583 |
|
583 | |||
584 | isConfig = False |
|
584 | isConfig = False | |
585 | __profIndex = 0 |
|
585 | __profIndex = 0 | |
586 |
|
586 | |||
587 | code = None |
|
587 | code = None | |
588 |
|
588 | |||
589 | nCode = None |
|
589 | nCode = None | |
590 | nBaud = None |
|
590 | nBaud = None | |
591 |
|
591 | |||
592 | def __init__(self, **kwargs): |
|
592 | def __init__(self, **kwargs): | |
593 |
|
593 | |||
594 | Operation.__init__(self, **kwargs) |
|
594 | Operation.__init__(self, **kwargs) | |
595 |
|
595 | |||
596 | self.times = None |
|
596 | self.times = None | |
597 | self.osamp = None |
|
597 | self.osamp = None | |
598 | # self.__setValues = False |
|
598 | # self.__setValues = False | |
599 | self.isConfig = False |
|
599 | self.isConfig = False | |
600 | self.setupReq = False |
|
600 | self.setupReq = False | |
601 | def setup(self, code, osamp, dataOut): |
|
601 | def setup(self, code, osamp, dataOut): | |
602 |
|
602 | |||
603 | self.__profIndex = 0 |
|
603 | self.__profIndex = 0 | |
604 |
|
604 | |||
605 | self.code = code |
|
605 | self.code = code | |
606 |
|
606 | |||
607 | self.nCode = len(code) |
|
607 | self.nCode = len(code) | |
608 | self.nBaud = len(code[0]) |
|
608 | self.nBaud = len(code[0]) | |
609 |
|
609 | |||
610 | if (osamp != None) and (osamp >1): |
|
610 | if (osamp != None) and (osamp >1): | |
611 | self.osamp = osamp |
|
611 | self.osamp = osamp | |
612 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) |
|
612 | self.code = numpy.repeat(code, repeats=self.osamp, axis=1) | |
613 | self.nBaud = self.nBaud*self.osamp |
|
613 | self.nBaud = self.nBaud*self.osamp | |
614 |
|
614 | |||
615 | self.__nChannels = dataOut.nChannels |
|
615 | self.__nChannels = dataOut.nChannels | |
616 | self.__nProfiles = dataOut.nProfiles |
|
616 | self.__nProfiles = dataOut.nProfiles | |
617 | self.__nHeis = dataOut.nHeights |
|
617 | self.__nHeis = dataOut.nHeights | |
618 |
|
618 | |||
619 | if self.__nHeis < self.nBaud: |
|
619 | if self.__nHeis < self.nBaud: | |
620 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) |
|
620 | raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)) | |
621 |
|
621 | |||
622 | #Frequency |
|
622 | #Frequency | |
623 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
623 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
624 |
|
624 | |||
625 | __codeBuffer[:,0:self.nBaud] = self.code |
|
625 | __codeBuffer[:,0:self.nBaud] = self.code | |
626 |
|
626 | |||
627 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
627 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
628 |
|
628 | |||
629 | if dataOut.flagDataAsBlock: |
|
629 | if dataOut.flagDataAsBlock: | |
630 |
|
630 | |||
631 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
631 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
632 |
|
632 | |||
633 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
633 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
634 |
|
634 | |||
635 | else: |
|
635 | else: | |
636 |
|
636 | |||
637 | #Time |
|
637 | #Time | |
638 | self.ndatadec = self.__nHeis #- self.nBaud + 1 |
|
638 | self.ndatadec = self.__nHeis #- self.nBaud + 1 | |
639 |
|
639 | |||
640 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
640 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
641 |
|
641 | |||
642 | def __convolutionInFreq(self, data): |
|
642 | def __convolutionInFreq(self, data): | |
643 |
|
643 | |||
644 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
644 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
645 |
|
645 | |||
646 | fft_data = numpy.fft.fft(data, axis=1) |
|
646 | fft_data = numpy.fft.fft(data, axis=1) | |
647 |
|
647 | |||
648 | conv = fft_data*fft_code |
|
648 | conv = fft_data*fft_code | |
649 |
|
649 | |||
650 | data = numpy.fft.ifft(conv,axis=1) |
|
650 | data = numpy.fft.ifft(conv,axis=1) | |
651 |
|
651 | |||
652 | return data |
|
652 | return data | |
653 |
|
653 | |||
654 | def __convolutionInFreqOpt(self, data): |
|
654 | def __convolutionInFreqOpt(self, data): | |
655 |
|
655 | |||
656 | raise NotImplementedError |
|
656 | raise NotImplementedError | |
657 |
|
657 | |||
658 | def __convolutionInTime(self, data): |
|
658 | def __convolutionInTime(self, data): | |
659 |
|
659 | |||
660 | code = self.code[self.__profIndex] |
|
660 | code = self.code[self.__profIndex] | |
661 | for i in range(self.__nChannels): |
|
661 | for i in range(self.__nChannels): | |
662 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
662 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] | |
663 |
|
663 | |||
664 | return self.datadecTime |
|
664 | return self.datadecTime | |
665 |
|
665 | |||
666 | def __convolutionByBlockInTime(self, data): |
|
666 | def __convolutionByBlockInTime(self, data): | |
667 |
|
667 | |||
668 | repetitions = self.__nProfiles / self.nCode |
|
668 | repetitions = self.__nProfiles / self.nCode | |
669 |
|
669 | |||
670 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) |
|
670 | junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize)) | |
671 | junk = junk.flatten() |
|
671 | junk = junk.flatten() | |
672 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) |
|
672 | code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud)) | |
673 | profilesList = range(self.__nProfiles) |
|
673 | profilesList = range(self.__nProfiles) | |
674 |
|
674 | |||
675 | for i in range(self.__nChannels): |
|
675 | for i in range(self.__nChannels): | |
676 | for j in profilesList: |
|
676 | for j in profilesList: | |
677 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] |
|
677 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:] | |
678 | return self.datadecTime |
|
678 | return self.datadecTime | |
679 |
|
679 | |||
680 | def __convolutionByBlockInFreq(self, data): |
|
680 | def __convolutionByBlockInFreq(self, data): | |
681 |
|
681 | |||
682 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") |
|
682 | raise NotImplementedError("Decoder by frequency fro Blocks not implemented") | |
683 |
|
683 | |||
684 |
|
684 | |||
685 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
685 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
686 |
|
686 | |||
687 | fft_data = numpy.fft.fft(data, axis=2) |
|
687 | fft_data = numpy.fft.fft(data, axis=2) | |
688 |
|
688 | |||
689 | conv = fft_data*fft_code |
|
689 | conv = fft_data*fft_code | |
690 |
|
690 | |||
691 | data = numpy.fft.ifft(conv,axis=2) |
|
691 | data = numpy.fft.ifft(conv,axis=2) | |
692 |
|
692 | |||
693 | return data |
|
693 | return data | |
694 |
|
694 | |||
695 |
|
695 | |||
696 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): |
|
696 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None): | |
697 |
|
697 | |||
698 | if dataOut.flagDecodeData: |
|
698 | if dataOut.flagDecodeData: | |
699 | print("This data is already decoded, recoding again ...") |
|
699 | print("This data is already decoded, recoding again ...") | |
700 |
|
700 | |||
701 | if not self.isConfig: |
|
701 | if not self.isConfig: | |
702 |
|
702 | |||
703 | if code is None: |
|
703 | if code is None: | |
704 | if dataOut.code is None: |
|
704 | if dataOut.code is None: | |
705 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) |
|
705 | raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type) | |
706 |
|
706 | |||
707 | code = dataOut.code |
|
707 | code = dataOut.code | |
708 | else: |
|
708 | else: | |
709 | code = numpy.array(code).reshape(nCode,nBaud) |
|
709 | code = numpy.array(code).reshape(nCode,nBaud) | |
710 | self.setup(code, osamp, dataOut) |
|
710 | self.setup(code, osamp, dataOut) | |
711 |
|
711 | |||
712 | self.isConfig = True |
|
712 | self.isConfig = True | |
713 |
|
713 | |||
714 | if mode == 3: |
|
714 | if mode == 3: | |
715 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) |
|
715 | sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode) | |
716 |
|
716 | |||
717 | if times != None: |
|
717 | if times != None: | |
718 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") |
|
718 | sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n") | |
719 |
|
719 | |||
720 | if self.code is None: |
|
720 | if self.code is None: | |
721 | print("Fail decoding: Code is not defined.") |
|
721 | print("Fail decoding: Code is not defined.") | |
722 | return |
|
722 | return | |
723 |
|
723 | |||
724 | self.__nProfiles = dataOut.nProfiles |
|
724 | self.__nProfiles = dataOut.nProfiles | |
725 | datadec = None |
|
725 | datadec = None | |
726 |
|
726 | |||
727 | if mode == 3: |
|
727 | if mode == 3: | |
728 | mode = 0 |
|
728 | mode = 0 | |
729 |
|
729 | |||
730 | if dataOut.flagDataAsBlock: |
|
730 | if dataOut.flagDataAsBlock: | |
731 | """ |
|
731 | """ | |
732 | Decoding when data have been read as block, |
|
732 | Decoding when data have been read as block, | |
733 | """ |
|
733 | """ | |
734 |
|
734 | |||
735 | if mode == 0: |
|
735 | if mode == 0: | |
736 | datadec = self.__convolutionByBlockInTime(dataOut.data) |
|
736 | datadec = self.__convolutionByBlockInTime(dataOut.data) | |
737 | if mode == 1: |
|
737 | if mode == 1: | |
738 | datadec = self.__convolutionByBlockInFreq(dataOut.data) |
|
738 | datadec = self.__convolutionByBlockInFreq(dataOut.data) | |
739 | else: |
|
739 | else: | |
740 | """ |
|
740 | """ | |
741 | Decoding when data have been read profile by profile |
|
741 | Decoding when data have been read profile by profile | |
742 | """ |
|
742 | """ | |
743 | if mode == 0: |
|
743 | if mode == 0: | |
744 | datadec = self.__convolutionInTime(dataOut.data) |
|
744 | datadec = self.__convolutionInTime(dataOut.data) | |
745 |
|
745 | |||
746 | if mode == 1: |
|
746 | if mode == 1: | |
747 | datadec = self.__convolutionInFreq(dataOut.data) |
|
747 | datadec = self.__convolutionInFreq(dataOut.data) | |
748 |
|
748 | |||
749 | if mode == 2: |
|
749 | if mode == 2: | |
750 | datadec = self.__convolutionInFreqOpt(dataOut.data) |
|
750 | datadec = self.__convolutionInFreqOpt(dataOut.data) | |
751 |
|
751 | |||
752 | if datadec is None: |
|
752 | if datadec is None: | |
753 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) |
|
753 | raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode) | |
754 |
|
754 | |||
755 | dataOut.code = self.code |
|
755 | dataOut.code = self.code | |
756 | dataOut.nCode = self.nCode |
|
756 | dataOut.nCode = self.nCode | |
757 | dataOut.nBaud = self.nBaud |
|
757 | dataOut.nBaud = self.nBaud | |
758 |
|
758 | |||
759 | dataOut.data = datadec |
|
759 | dataOut.data = datadec | |
760 |
|
760 | |||
761 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] |
|
761 | dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]] | |
762 |
|
762 | |||
763 | dataOut.flagDecodeData = True #asumo q la data esta decodificada |
|
763 | dataOut.flagDecodeData = True #asumo q la data esta decodificada | |
764 |
|
764 | |||
765 | if self.__profIndex == self.nCode-1: |
|
765 | if self.__profIndex == self.nCode-1: | |
766 | self.__profIndex = 0 |
|
766 | self.__profIndex = 0 | |
767 | return dataOut |
|
767 | return dataOut | |
768 |
|
768 | |||
769 | self.__profIndex += 1 |
|
769 | self.__profIndex += 1 | |
770 |
|
770 | |||
771 | return dataOut |
|
771 | return dataOut | |
772 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
772 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
773 |
|
773 | |||
774 |
|
774 | |||
775 | class ProfileConcat(Operation): |
|
775 | class ProfileConcat(Operation): | |
776 |
|
776 | |||
777 | isConfig = False |
|
777 | isConfig = False | |
778 | buffer = None |
|
778 | buffer = None | |
779 |
|
779 | |||
780 | def __init__(self, **kwargs): |
|
780 | def __init__(self, **kwargs): | |
781 |
|
781 | |||
782 | Operation.__init__(self, **kwargs) |
|
782 | Operation.__init__(self, **kwargs) | |
783 | self.profileIndex = 0 |
|
783 | self.profileIndex = 0 | |
784 |
|
784 | |||
785 | def reset(self): |
|
785 | def reset(self): | |
786 | self.buffer = numpy.zeros_like(self.buffer) |
|
786 | self.buffer = numpy.zeros_like(self.buffer) | |
787 | self.start_index = 0 |
|
787 | self.start_index = 0 | |
788 | self.times = 1 |
|
788 | self.times = 1 | |
789 |
|
789 | |||
790 | def setup(self, data, m, n=1): |
|
790 | def setup(self, data, m, n=1): | |
791 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
791 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
792 | self.nHeights = data.shape[1]#.nHeights |
|
792 | self.nHeights = data.shape[1]#.nHeights | |
793 | self.start_index = 0 |
|
793 | self.start_index = 0 | |
794 | self.times = 1 |
|
794 | self.times = 1 | |
795 |
|
795 | |||
796 | def concat(self, data): |
|
796 | def concat(self, data): | |
797 |
|
797 | |||
798 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() |
|
798 | self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy() | |
799 | self.start_index = self.start_index + self.nHeights |
|
799 | self.start_index = self.start_index + self.nHeights | |
800 |
|
800 | |||
801 | def run(self, dataOut, m): |
|
801 | def run(self, dataOut, m): | |
802 | dataOut.flagNoData = True |
|
802 | dataOut.flagNoData = True | |
803 |
|
803 | |||
804 | if not self.isConfig: |
|
804 | if not self.isConfig: | |
805 | self.setup(dataOut.data, m, 1) |
|
805 | self.setup(dataOut.data, m, 1) | |
806 | self.isConfig = True |
|
806 | self.isConfig = True | |
807 |
|
807 | |||
808 | if dataOut.flagDataAsBlock: |
|
808 | if dataOut.flagDataAsBlock: | |
809 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") |
|
809 | raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False") | |
810 |
|
810 | |||
811 | else: |
|
811 | else: | |
812 | self.concat(dataOut.data) |
|
812 | self.concat(dataOut.data) | |
813 | self.times += 1 |
|
813 | self.times += 1 | |
814 | if self.times > m: |
|
814 | if self.times > m: | |
815 | dataOut.data = self.buffer |
|
815 | dataOut.data = self.buffer | |
816 | self.reset() |
|
816 | self.reset() | |
817 | dataOut.flagNoData = False |
|
817 | dataOut.flagNoData = False | |
818 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
818 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
819 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
819 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
820 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m |
|
820 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m | |
821 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
821 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
822 | dataOut.ippSeconds *= m |
|
822 | dataOut.ippSeconds *= m | |
823 | return dataOut |
|
823 | return dataOut | |
824 |
|
824 | |||
825 | class ProfileSelector(Operation): |
|
825 | class ProfileSelector(Operation): | |
826 |
|
826 | |||
827 | profileIndex = None |
|
827 | profileIndex = None | |
828 | # Tamanho total de los perfiles |
|
828 | # Tamanho total de los perfiles | |
829 | nProfiles = None |
|
829 | nProfiles = None | |
830 |
|
830 | |||
831 | def __init__(self, **kwargs): |
|
831 | def __init__(self, **kwargs): | |
832 |
|
832 | |||
833 | Operation.__init__(self, **kwargs) |
|
833 | Operation.__init__(self, **kwargs) | |
834 | self.profileIndex = 0 |
|
834 | self.profileIndex = 0 | |
835 |
|
835 | |||
836 | def incProfileIndex(self): |
|
836 | def incProfileIndex(self): | |
837 |
|
837 | |||
838 | self.profileIndex += 1 |
|
838 | self.profileIndex += 1 | |
839 |
|
839 | |||
840 | if self.profileIndex >= self.nProfiles: |
|
840 | if self.profileIndex >= self.nProfiles: | |
841 | self.profileIndex = 0 |
|
841 | self.profileIndex = 0 | |
842 |
|
842 | |||
843 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): |
|
843 | def isThisProfileInRange(self, profileIndex, minIndex, maxIndex): | |
844 |
|
844 | |||
845 | if profileIndex < minIndex: |
|
845 | if profileIndex < minIndex: | |
846 | return False |
|
846 | return False | |
847 |
|
847 | |||
848 | if profileIndex > maxIndex: |
|
848 | if profileIndex > maxIndex: | |
849 | return False |
|
849 | return False | |
850 |
|
850 | |||
851 | return True |
|
851 | return True | |
852 |
|
852 | |||
853 | def isThisProfileInList(self, profileIndex, profileList): |
|
853 | def isThisProfileInList(self, profileIndex, profileList): | |
854 |
|
854 | |||
855 | if profileIndex not in profileList: |
|
855 | if profileIndex not in profileList: | |
856 | return False |
|
856 | return False | |
857 |
|
857 | |||
858 | return True |
|
858 | return True | |
859 |
|
859 | |||
860 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): |
|
860 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None): | |
861 |
|
861 | |||
862 | """ |
|
862 | """ | |
863 | ProfileSelector: |
|
863 | ProfileSelector: | |
864 |
|
864 | |||
865 | Inputs: |
|
865 | Inputs: | |
866 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) |
|
866 | profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8) | |
867 |
|
867 | |||
868 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) |
|
868 | profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30) | |
869 |
|
869 | |||
870 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) |
|
870 | rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256)) | |
871 |
|
871 | |||
872 | """ |
|
872 | """ | |
873 |
|
873 | |||
874 | if rangeList is not None: |
|
874 | if rangeList is not None: | |
875 | if type(rangeList[0]) not in (tuple, list): |
|
875 | if type(rangeList[0]) not in (tuple, list): | |
876 | rangeList = [rangeList] |
|
876 | rangeList = [rangeList] | |
877 |
|
877 | |||
878 | dataOut.flagNoData = True |
|
878 | dataOut.flagNoData = True | |
879 |
|
879 | |||
880 | if dataOut.flagDataAsBlock: |
|
880 | if dataOut.flagDataAsBlock: | |
881 | """ |
|
881 | """ | |
882 | data dimension = [nChannels, nProfiles, nHeis] |
|
882 | data dimension = [nChannels, nProfiles, nHeis] | |
883 | """ |
|
883 | """ | |
884 | if profileList != None: |
|
884 | if profileList != None: | |
885 | dataOut.data = dataOut.data[:,profileList,:] |
|
885 | dataOut.data = dataOut.data[:,profileList,:] | |
886 |
|
886 | |||
887 | if profileRangeList != None: |
|
887 | if profileRangeList != None: | |
888 | minIndex = profileRangeList[0] |
|
888 | minIndex = profileRangeList[0] | |
889 | maxIndex = profileRangeList[1] |
|
889 | maxIndex = profileRangeList[1] | |
890 | profileList = list(range(minIndex, maxIndex+1)) |
|
890 | profileList = list(range(minIndex, maxIndex+1)) | |
891 |
|
891 | |||
892 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] |
|
892 | dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:] | |
893 |
|
893 | |||
894 | if rangeList != None: |
|
894 | if rangeList != None: | |
895 |
|
895 | |||
896 | profileList = [] |
|
896 | profileList = [] | |
897 |
|
897 | |||
898 | for thisRange in rangeList: |
|
898 | for thisRange in rangeList: | |
899 | minIndex = thisRange[0] |
|
899 | minIndex = thisRange[0] | |
900 | maxIndex = thisRange[1] |
|
900 | maxIndex = thisRange[1] | |
901 |
|
901 | |||
902 | profileList.extend(list(range(minIndex, maxIndex+1))) |
|
902 | profileList.extend(list(range(minIndex, maxIndex+1))) | |
903 |
|
903 | |||
904 | dataOut.data = dataOut.data[:,profileList,:] |
|
904 | dataOut.data = dataOut.data[:,profileList,:] | |
905 |
|
905 | |||
906 | dataOut.nProfiles = len(profileList) |
|
906 | dataOut.nProfiles = len(profileList) | |
907 | dataOut.profileIndex = dataOut.nProfiles - 1 |
|
907 | dataOut.profileIndex = dataOut.nProfiles - 1 | |
908 | dataOut.flagNoData = False |
|
908 | dataOut.flagNoData = False | |
909 |
|
909 | |||
910 | return dataOut |
|
910 | return dataOut | |
911 |
|
911 | |||
912 | """ |
|
912 | """ | |
913 | data dimension = [nChannels, nHeis] |
|
913 | data dimension = [nChannels, nHeis] | |
914 | """ |
|
914 | """ | |
915 |
|
915 | |||
916 | if profileList != None: |
|
916 | if profileList != None: | |
917 |
|
917 | |||
918 | if self.isThisProfileInList(dataOut.profileIndex, profileList): |
|
918 | if self.isThisProfileInList(dataOut.profileIndex, profileList): | |
919 |
|
919 | |||
920 | self.nProfiles = len(profileList) |
|
920 | self.nProfiles = len(profileList) | |
921 | dataOut.nProfiles = self.nProfiles |
|
921 | dataOut.nProfiles = self.nProfiles | |
922 | dataOut.profileIndex = self.profileIndex |
|
922 | dataOut.profileIndex = self.profileIndex | |
923 | dataOut.flagNoData = False |
|
923 | dataOut.flagNoData = False | |
924 |
|
924 | |||
925 | self.incProfileIndex() |
|
925 | self.incProfileIndex() | |
926 | return dataOut |
|
926 | return dataOut | |
927 |
|
927 | |||
928 | if profileRangeList != None: |
|
928 | if profileRangeList != None: | |
929 |
|
929 | |||
930 | minIndex = profileRangeList[0] |
|
930 | minIndex = profileRangeList[0] | |
931 | maxIndex = profileRangeList[1] |
|
931 | maxIndex = profileRangeList[1] | |
932 |
|
932 | |||
933 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
933 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
934 |
|
934 | |||
935 | self.nProfiles = maxIndex - minIndex + 1 |
|
935 | self.nProfiles = maxIndex - minIndex + 1 | |
936 | dataOut.nProfiles = self.nProfiles |
|
936 | dataOut.nProfiles = self.nProfiles | |
937 | dataOut.profileIndex = self.profileIndex |
|
937 | dataOut.profileIndex = self.profileIndex | |
938 | dataOut.flagNoData = False |
|
938 | dataOut.flagNoData = False | |
939 |
|
939 | |||
940 | self.incProfileIndex() |
|
940 | self.incProfileIndex() | |
941 | return dataOut |
|
941 | return dataOut | |
942 |
|
942 | |||
943 | if rangeList != None: |
|
943 | if rangeList != None: | |
944 |
|
944 | |||
945 | nProfiles = 0 |
|
945 | nProfiles = 0 | |
946 |
|
946 | |||
947 | for thisRange in rangeList: |
|
947 | for thisRange in rangeList: | |
948 | minIndex = thisRange[0] |
|
948 | minIndex = thisRange[0] | |
949 | maxIndex = thisRange[1] |
|
949 | maxIndex = thisRange[1] | |
950 |
|
950 | |||
951 | nProfiles += maxIndex - minIndex + 1 |
|
951 | nProfiles += maxIndex - minIndex + 1 | |
952 |
|
952 | |||
953 | for thisRange in rangeList: |
|
953 | for thisRange in rangeList: | |
954 |
|
954 | |||
955 | minIndex = thisRange[0] |
|
955 | minIndex = thisRange[0] | |
956 | maxIndex = thisRange[1] |
|
956 | maxIndex = thisRange[1] | |
957 |
|
957 | |||
958 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): |
|
958 | if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex): | |
959 |
|
959 | |||
960 | self.nProfiles = nProfiles |
|
960 | self.nProfiles = nProfiles | |
961 | dataOut.nProfiles = self.nProfiles |
|
961 | dataOut.nProfiles = self.nProfiles | |
962 | dataOut.profileIndex = self.profileIndex |
|
962 | dataOut.profileIndex = self.profileIndex | |
963 | dataOut.flagNoData = False |
|
963 | dataOut.flagNoData = False | |
964 |
|
964 | |||
965 | self.incProfileIndex() |
|
965 | self.incProfileIndex() | |
966 |
|
966 | |||
967 | break |
|
967 | break | |
968 |
|
968 | |||
969 | return dataOut |
|
969 | return dataOut | |
970 |
|
970 | |||
971 |
|
971 | |||
972 | if beam != None: #beam is only for AMISR data |
|
972 | if beam != None: #beam is only for AMISR data | |
973 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): |
|
973 | if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]): | |
974 | dataOut.flagNoData = False |
|
974 | dataOut.flagNoData = False | |
975 | dataOut.profileIndex = self.profileIndex |
|
975 | dataOut.profileIndex = self.profileIndex | |
976 |
|
976 | |||
977 | self.incProfileIndex() |
|
977 | self.incProfileIndex() | |
978 |
|
978 | |||
979 | return dataOut |
|
979 | return dataOut | |
980 |
|
980 | |||
981 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") |
|
981 | raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter") | |
982 |
|
982 | |||
983 | #return False |
|
983 | #return False | |
984 | return dataOut |
|
984 | return dataOut | |
985 |
|
985 | |||
986 | class Reshaper(Operation): |
|
986 | class Reshaper(Operation): | |
987 |
|
987 | |||
988 | def __init__(self, **kwargs): |
|
988 | def __init__(self, **kwargs): | |
989 |
|
989 | |||
990 | Operation.__init__(self, **kwargs) |
|
990 | Operation.__init__(self, **kwargs) | |
991 |
|
991 | |||
992 | self.__buffer = None |
|
992 | self.__buffer = None | |
993 | self.__nitems = 0 |
|
993 | self.__nitems = 0 | |
994 |
|
994 | |||
995 | def __appendProfile(self, dataOut, nTxs): |
|
995 | def __appendProfile(self, dataOut, nTxs): | |
996 |
|
996 | |||
997 | if self.__buffer is None: |
|
997 | if self.__buffer is None: | |
998 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) |
|
998 | shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) ) | |
999 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) |
|
999 | self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype) | |
1000 |
|
1000 | |||
1001 | ini = dataOut.nHeights * self.__nitems |
|
1001 | ini = dataOut.nHeights * self.__nitems | |
1002 | end = ini + dataOut.nHeights |
|
1002 | end = ini + dataOut.nHeights | |
1003 |
|
1003 | |||
1004 | self.__buffer[:, ini:end] = dataOut.data |
|
1004 | self.__buffer[:, ini:end] = dataOut.data | |
1005 |
|
1005 | |||
1006 | self.__nitems += 1 |
|
1006 | self.__nitems += 1 | |
1007 |
|
1007 | |||
1008 | return int(self.__nitems*nTxs) |
|
1008 | return int(self.__nitems*nTxs) | |
1009 |
|
1009 | |||
1010 | def __getBuffer(self): |
|
1010 | def __getBuffer(self): | |
1011 |
|
1011 | |||
1012 | if self.__nitems == int(1./self.__nTxs): |
|
1012 | if self.__nitems == int(1./self.__nTxs): | |
1013 |
|
1013 | |||
1014 | self.__nitems = 0 |
|
1014 | self.__nitems = 0 | |
1015 |
|
1015 | |||
1016 | return self.__buffer.copy() |
|
1016 | return self.__buffer.copy() | |
1017 |
|
1017 | |||
1018 | return None |
|
1018 | return None | |
1019 |
|
1019 | |||
1020 | def __checkInputs(self, dataOut, shape, nTxs): |
|
1020 | def __checkInputs(self, dataOut, shape, nTxs): | |
1021 |
|
1021 | |||
1022 | if shape is None and nTxs is None: |
|
1022 | if shape is None and nTxs is None: | |
1023 | raise ValueError("Reshaper: shape of factor should be defined") |
|
1023 | raise ValueError("Reshaper: shape of factor should be defined") | |
1024 |
|
1024 | |||
1025 | if nTxs: |
|
1025 | if nTxs: | |
1026 | if nTxs < 0: |
|
1026 | if nTxs < 0: | |
1027 | raise ValueError("nTxs should be greater than 0") |
|
1027 | raise ValueError("nTxs should be greater than 0") | |
1028 |
|
1028 | |||
1029 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: |
|
1029 | if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0: | |
1030 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) |
|
1030 | raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))) | |
1031 |
|
1031 | |||
1032 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] |
|
1032 | shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs] | |
1033 |
|
1033 | |||
1034 | return shape, nTxs |
|
1034 | return shape, nTxs | |
1035 |
|
1035 | |||
1036 | if len(shape) != 2 and len(shape) != 3: |
|
1036 | if len(shape) != 2 and len(shape) != 3: | |
1037 | raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)) |
|
1037 | raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)) | |
1038 |
|
1038 | |||
1039 | if len(shape) == 2: |
|
1039 | if len(shape) == 2: | |
1040 | shape_tuple = [dataOut.nChannels] |
|
1040 | shape_tuple = [dataOut.nChannels] | |
1041 | shape_tuple.extend(shape) |
|
1041 | shape_tuple.extend(shape) | |
1042 | else: |
|
1042 | else: | |
1043 | shape_tuple = list(shape) |
|
1043 | shape_tuple = list(shape) | |
1044 |
|
1044 | |||
1045 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles |
|
1045 | nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles | |
1046 |
|
1046 | |||
1047 | return shape_tuple, nTxs |
|
1047 | return shape_tuple, nTxs | |
1048 |
|
1048 | |||
1049 | def run(self, dataOut, shape=None, nTxs=None): |
|
1049 | def run(self, dataOut, shape=None, nTxs=None): | |
1050 |
|
1050 | |||
1051 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) |
|
1051 | shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs) | |
1052 |
|
1052 | |||
1053 | dataOut.flagNoData = True |
|
1053 | dataOut.flagNoData = True | |
1054 | profileIndex = None |
|
1054 | profileIndex = None | |
1055 |
|
1055 | |||
1056 | if dataOut.flagDataAsBlock: |
|
1056 | if dataOut.flagDataAsBlock: | |
1057 |
|
1057 | |||
1058 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
1058 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
1059 | dataOut.flagNoData = False |
|
1059 | dataOut.flagNoData = False | |
1060 |
|
1060 | |||
1061 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 |
|
1061 | profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1 | |
1062 |
|
1062 | |||
1063 | else: |
|
1063 | else: | |
1064 |
|
1064 | |||
1065 | if self.__nTxs < 1: |
|
1065 | if self.__nTxs < 1: | |
1066 |
|
1066 | |||
1067 | self.__appendProfile(dataOut, self.__nTxs) |
|
1067 | self.__appendProfile(dataOut, self.__nTxs) | |
1068 | new_data = self.__getBuffer() |
|
1068 | new_data = self.__getBuffer() | |
1069 |
|
1069 | |||
1070 | if new_data is not None: |
|
1070 | if new_data is not None: | |
1071 | dataOut.data = new_data |
|
1071 | dataOut.data = new_data | |
1072 | dataOut.flagNoData = False |
|
1072 | dataOut.flagNoData = False | |
1073 |
|
1073 | |||
1074 | profileIndex = dataOut.profileIndex*nTxs |
|
1074 | profileIndex = dataOut.profileIndex*nTxs | |
1075 |
|
1075 | |||
1076 | else: |
|
1076 | else: | |
1077 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") |
|
1077 | raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)") | |
1078 |
|
1078 | |||
1079 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1079 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1080 |
|
1080 | |||
1081 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] |
|
1081 | dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0] | |
1082 |
|
1082 | |||
1083 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) |
|
1083 | dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs) | |
1084 |
|
1084 | |||
1085 | dataOut.profileIndex = profileIndex |
|
1085 | dataOut.profileIndex = profileIndex | |
1086 |
|
1086 | |||
1087 | dataOut.ippSeconds /= self.__nTxs |
|
1087 | dataOut.ippSeconds /= self.__nTxs | |
1088 |
|
1088 | |||
1089 | return dataOut |
|
1089 | return dataOut | |
1090 |
|
1090 | |||
1091 | class SplitProfiles(Operation): |
|
1091 | class SplitProfiles(Operation): | |
1092 |
|
1092 | |||
1093 | def __init__(self, **kwargs): |
|
1093 | def __init__(self, **kwargs): | |
1094 |
|
1094 | |||
1095 | Operation.__init__(self, **kwargs) |
|
1095 | Operation.__init__(self, **kwargs) | |
1096 |
|
1096 | |||
1097 | def run(self, dataOut, n): |
|
1097 | def run(self, dataOut, n): | |
1098 |
|
1098 | |||
1099 | dataOut.flagNoData = True |
|
1099 | dataOut.flagNoData = True | |
1100 | profileIndex = None |
|
1100 | profileIndex = None | |
1101 |
|
1101 | |||
1102 | if dataOut.flagDataAsBlock: |
|
1102 | if dataOut.flagDataAsBlock: | |
1103 |
|
1103 | |||
1104 | #nchannels, nprofiles, nsamples |
|
1104 | #nchannels, nprofiles, nsamples | |
1105 | shape = dataOut.data.shape |
|
1105 | shape = dataOut.data.shape | |
1106 |
|
1106 | |||
1107 | if shape[2] % n != 0: |
|
1107 | if shape[2] % n != 0: | |
1108 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) |
|
1108 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])) | |
1109 |
|
1109 | |||
1110 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) |
|
1110 | new_shape = shape[0], shape[1]*n, int(shape[2]/n) | |
1111 |
|
1111 | |||
1112 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1112 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1113 | dataOut.flagNoData = False |
|
1113 | dataOut.flagNoData = False | |
1114 |
|
1114 | |||
1115 | profileIndex = int(dataOut.nProfiles/n) - 1 |
|
1115 | profileIndex = int(dataOut.nProfiles/n) - 1 | |
1116 |
|
1116 | |||
1117 | else: |
|
1117 | else: | |
1118 |
|
1118 | |||
1119 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") |
|
1119 | raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)") | |
1120 |
|
1120 | |||
1121 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1121 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1122 |
|
1122 | |||
1123 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] |
|
1123 | dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0] | |
1124 |
|
1124 | |||
1125 | dataOut.nProfiles = int(dataOut.nProfiles*n) |
|
1125 | dataOut.nProfiles = int(dataOut.nProfiles*n) | |
1126 |
|
1126 | |||
1127 | dataOut.profileIndex = profileIndex |
|
1127 | dataOut.profileIndex = profileIndex | |
1128 |
|
1128 | |||
1129 | dataOut.ippSeconds /= n |
|
1129 | dataOut.ippSeconds /= n | |
1130 |
|
1130 | |||
1131 | return dataOut |
|
1131 | return dataOut | |
1132 |
|
1132 | |||
1133 | class CombineProfiles(Operation): |
|
1133 | class CombineProfiles(Operation): | |
1134 | def __init__(self, **kwargs): |
|
1134 | def __init__(self, **kwargs): | |
1135 |
|
1135 | |||
1136 | Operation.__init__(self, **kwargs) |
|
1136 | Operation.__init__(self, **kwargs) | |
1137 |
|
1137 | |||
1138 | self.__remData = None |
|
1138 | self.__remData = None | |
1139 | self.__profileIndex = 0 |
|
1139 | self.__profileIndex = 0 | |
1140 |
|
1140 | |||
1141 | def run(self, dataOut, n): |
|
1141 | def run(self, dataOut, n): | |
1142 |
|
1142 | |||
1143 | dataOut.flagNoData = True |
|
1143 | dataOut.flagNoData = True | |
1144 | profileIndex = None |
|
1144 | profileIndex = None | |
1145 |
|
1145 | |||
1146 | if dataOut.flagDataAsBlock: |
|
1146 | if dataOut.flagDataAsBlock: | |
1147 |
|
1147 | |||
1148 | #nchannels, nprofiles, nsamples |
|
1148 | #nchannels, nprofiles, nsamples | |
1149 | shape = dataOut.data.shape |
|
1149 | shape = dataOut.data.shape | |
1150 | new_shape = shape[0], shape[1]/n, shape[2]*n |
|
1150 | new_shape = shape[0], shape[1]/n, shape[2]*n | |
1151 |
|
1151 | |||
1152 | if shape[1] % n != 0: |
|
1152 | if shape[1] % n != 0: | |
1153 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) |
|
1153 | raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])) | |
1154 |
|
1154 | |||
1155 | dataOut.data = numpy.reshape(dataOut.data, new_shape) |
|
1155 | dataOut.data = numpy.reshape(dataOut.data, new_shape) | |
1156 | dataOut.flagNoData = False |
|
1156 | dataOut.flagNoData = False | |
1157 |
|
1157 | |||
1158 | profileIndex = int(dataOut.nProfiles*n) - 1 |
|
1158 | profileIndex = int(dataOut.nProfiles*n) - 1 | |
1159 |
|
1159 | |||
1160 | else: |
|
1160 | else: | |
1161 |
|
1161 | |||
1162 | #nchannels, nsamples |
|
1162 | #nchannels, nsamples | |
1163 | if self.__remData is None: |
|
1163 | if self.__remData is None: | |
1164 | newData = dataOut.data |
|
1164 | newData = dataOut.data | |
1165 | else: |
|
1165 | else: | |
1166 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) |
|
1166 | newData = numpy.concatenate((self.__remData, dataOut.data), axis=1) | |
1167 |
|
1167 | |||
1168 | self.__profileIndex += 1 |
|
1168 | self.__profileIndex += 1 | |
1169 |
|
1169 | |||
1170 | if self.__profileIndex < n: |
|
1170 | if self.__profileIndex < n: | |
1171 | self.__remData = newData |
|
1171 | self.__remData = newData | |
1172 | #continue |
|
1172 | #continue | |
1173 | return |
|
1173 | return | |
1174 |
|
1174 | |||
1175 | self.__profileIndex = 0 |
|
1175 | self.__profileIndex = 0 | |
1176 | self.__remData = None |
|
1176 | self.__remData = None | |
1177 |
|
1177 | |||
1178 | dataOut.data = newData |
|
1178 | dataOut.data = newData | |
1179 | dataOut.flagNoData = False |
|
1179 | dataOut.flagNoData = False | |
1180 |
|
1180 | |||
1181 | profileIndex = dataOut.profileIndex/n |
|
1181 | profileIndex = dataOut.profileIndex/n | |
1182 |
|
1182 | |||
1183 |
|
1183 | |||
1184 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1184 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1185 |
|
1185 | |||
1186 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] |
|
1186 | dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0] | |
1187 |
|
1187 | |||
1188 | dataOut.nProfiles = int(dataOut.nProfiles/n) |
|
1188 | dataOut.nProfiles = int(dataOut.nProfiles/n) | |
1189 |
|
1189 | |||
1190 | dataOut.profileIndex = profileIndex |
|
1190 | dataOut.profileIndex = profileIndex | |
1191 |
|
1191 | |||
1192 | dataOut.ippSeconds *= n |
|
1192 | dataOut.ippSeconds *= n | |
1193 |
|
1193 | |||
1194 | return dataOut |
|
1194 | return dataOut | |
1195 | # import collections |
|
1195 | # import collections | |
1196 | # from scipy.stats import mode |
|
1196 | # from scipy.stats import mode | |
1197 | # |
|
1197 | # | |
1198 | # class Synchronize(Operation): |
|
1198 | # class Synchronize(Operation): | |
1199 | # |
|
1199 | # | |
1200 | # isConfig = False |
|
1200 | # isConfig = False | |
1201 | # __profIndex = 0 |
|
1201 | # __profIndex = 0 | |
1202 | # |
|
1202 | # | |
1203 | # def __init__(self, **kwargs): |
|
1203 | # def __init__(self, **kwargs): | |
1204 | # |
|
1204 | # | |
1205 | # Operation.__init__(self, **kwargs) |
|
1205 | # Operation.__init__(self, **kwargs) | |
1206 | # # self.isConfig = False |
|
1206 | # # self.isConfig = False | |
1207 | # self.__powBuffer = None |
|
1207 | # self.__powBuffer = None | |
1208 | # self.__startIndex = 0 |
|
1208 | # self.__startIndex = 0 | |
1209 | # self.__pulseFound = False |
|
1209 | # self.__pulseFound = False | |
1210 | # |
|
1210 | # | |
1211 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): |
|
1211 | # def __findTxPulse(self, dataOut, channel=0, pulse_with = None): | |
1212 | # |
|
1212 | # | |
1213 | # #Read data |
|
1213 | # #Read data | |
1214 | # |
|
1214 | # | |
1215 | # powerdB = dataOut.getPower(channel = channel) |
|
1215 | # powerdB = dataOut.getPower(channel = channel) | |
1216 | # noisedB = dataOut.getNoise(channel = channel)[0] |
|
1216 | # noisedB = dataOut.getNoise(channel = channel)[0] | |
1217 | # |
|
1217 | # | |
1218 | # self.__powBuffer.extend(powerdB.flatten()) |
|
1218 | # self.__powBuffer.extend(powerdB.flatten()) | |
1219 | # |
|
1219 | # | |
1220 | # dataArray = numpy.array(self.__powBuffer) |
|
1220 | # dataArray = numpy.array(self.__powBuffer) | |
1221 | # |
|
1221 | # | |
1222 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") |
|
1222 | # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same") | |
1223 | # |
|
1223 | # | |
1224 | # maxValue = numpy.nanmax(filteredPower) |
|
1224 | # maxValue = numpy.nanmax(filteredPower) | |
1225 | # |
|
1225 | # | |
1226 | # if maxValue < noisedB + 10: |
|
1226 | # if maxValue < noisedB + 10: | |
1227 | # #No se encuentra ningun pulso de transmision |
|
1227 | # #No se encuentra ningun pulso de transmision | |
1228 | # return None |
|
1228 | # return None | |
1229 | # |
|
1229 | # | |
1230 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] |
|
1230 | # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0] | |
1231 | # |
|
1231 | # | |
1232 | # if len(maxValuesIndex) < 2: |
|
1232 | # if len(maxValuesIndex) < 2: | |
1233 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX |
|
1233 | # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX | |
1234 | # return None |
|
1234 | # return None | |
1235 | # |
|
1235 | # | |
1236 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples |
|
1236 | # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples | |
1237 | # |
|
1237 | # | |
1238 | # #Seleccionar solo valores con un espaciamiento de nSamples |
|
1238 | # #Seleccionar solo valores con un espaciamiento de nSamples | |
1239 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) |
|
1239 | # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex) | |
1240 | # |
|
1240 | # | |
1241 | # if len(pulseIndex) < 2: |
|
1241 | # if len(pulseIndex) < 2: | |
1242 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1242 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1243 | # return None |
|
1243 | # return None | |
1244 | # |
|
1244 | # | |
1245 | # spacing = pulseIndex[1:] - pulseIndex[:-1] |
|
1245 | # spacing = pulseIndex[1:] - pulseIndex[:-1] | |
1246 | # |
|
1246 | # | |
1247 | # #remover senales que se distancien menos de 10 unidades o muestras |
|
1247 | # #remover senales que se distancien menos de 10 unidades o muestras | |
1248 | # #(No deberian existir IPP menor a 10 unidades) |
|
1248 | # #(No deberian existir IPP menor a 10 unidades) | |
1249 | # |
|
1249 | # | |
1250 | # realIndex = numpy.where(spacing > 10 )[0] |
|
1250 | # realIndex = numpy.where(spacing > 10 )[0] | |
1251 | # |
|
1251 | # | |
1252 | # if len(realIndex) < 2: |
|
1252 | # if len(realIndex) < 2: | |
1253 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 |
|
1253 | # #Solo se encontro un pulso de transmision con ancho mayor a 1 | |
1254 | # return None |
|
1254 | # return None | |
1255 | # |
|
1255 | # | |
1256 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) |
|
1256 | # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs) | |
1257 | # realPulseIndex = pulseIndex[realIndex] |
|
1257 | # realPulseIndex = pulseIndex[realIndex] | |
1258 | # |
|
1258 | # | |
1259 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] |
|
1259 | # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0] | |
1260 | # |
|
1260 | # | |
1261 | # print "IPP = %d samples" %period |
|
1261 | # print "IPP = %d samples" %period | |
1262 | # |
|
1262 | # | |
1263 | # self.__newNSamples = dataOut.nHeights #int(period) |
|
1263 | # self.__newNSamples = dataOut.nHeights #int(period) | |
1264 | # self.__startIndex = int(realPulseIndex[0]) |
|
1264 | # self.__startIndex = int(realPulseIndex[0]) | |
1265 | # |
|
1265 | # | |
1266 | # return 1 |
|
1266 | # return 1 | |
1267 | # |
|
1267 | # | |
1268 | # |
|
1268 | # | |
1269 | # def setup(self, nSamples, nChannels, buffer_size = 4): |
|
1269 | # def setup(self, nSamples, nChannels, buffer_size = 4): | |
1270 | # |
|
1270 | # | |
1271 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), |
|
1271 | # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float), | |
1272 | # maxlen = buffer_size*nSamples) |
|
1272 | # maxlen = buffer_size*nSamples) | |
1273 | # |
|
1273 | # | |
1274 | # bufferList = [] |
|
1274 | # bufferList = [] | |
1275 | # |
|
1275 | # | |
1276 | # for i in range(nChannels): |
|
1276 | # for i in range(nChannels): | |
1277 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, |
|
1277 | # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN, | |
1278 | # maxlen = buffer_size*nSamples) |
|
1278 | # maxlen = buffer_size*nSamples) | |
1279 | # |
|
1279 | # | |
1280 | # bufferList.append(bufferByChannel) |
|
1280 | # bufferList.append(bufferByChannel) | |
1281 | # |
|
1281 | # | |
1282 | # self.__nSamples = nSamples |
|
1282 | # self.__nSamples = nSamples | |
1283 | # self.__nChannels = nChannels |
|
1283 | # self.__nChannels = nChannels | |
1284 | # self.__bufferList = bufferList |
|
1284 | # self.__bufferList = bufferList | |
1285 | # |
|
1285 | # | |
1286 | # def run(self, dataOut, channel = 0): |
|
1286 | # def run(self, dataOut, channel = 0): | |
1287 | # |
|
1287 | # | |
1288 | # if not self.isConfig: |
|
1288 | # if not self.isConfig: | |
1289 | # nSamples = dataOut.nHeights |
|
1289 | # nSamples = dataOut.nHeights | |
1290 | # nChannels = dataOut.nChannels |
|
1290 | # nChannels = dataOut.nChannels | |
1291 | # self.setup(nSamples, nChannels) |
|
1291 | # self.setup(nSamples, nChannels) | |
1292 | # self.isConfig = True |
|
1292 | # self.isConfig = True | |
1293 | # |
|
1293 | # | |
1294 | # #Append new data to internal buffer |
|
1294 | # #Append new data to internal buffer | |
1295 | # for thisChannel in range(self.__nChannels): |
|
1295 | # for thisChannel in range(self.__nChannels): | |
1296 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1296 | # bufferByChannel = self.__bufferList[thisChannel] | |
1297 | # bufferByChannel.extend(dataOut.data[thisChannel]) |
|
1297 | # bufferByChannel.extend(dataOut.data[thisChannel]) | |
1298 | # |
|
1298 | # | |
1299 | # if self.__pulseFound: |
|
1299 | # if self.__pulseFound: | |
1300 | # self.__startIndex -= self.__nSamples |
|
1300 | # self.__startIndex -= self.__nSamples | |
1301 | # |
|
1301 | # | |
1302 | # #Finding Tx Pulse |
|
1302 | # #Finding Tx Pulse | |
1303 | # if not self.__pulseFound: |
|
1303 | # if not self.__pulseFound: | |
1304 | # indexFound = self.__findTxPulse(dataOut, channel) |
|
1304 | # indexFound = self.__findTxPulse(dataOut, channel) | |
1305 | # |
|
1305 | # | |
1306 | # if indexFound == None: |
|
1306 | # if indexFound == None: | |
1307 | # dataOut.flagNoData = True |
|
1307 | # dataOut.flagNoData = True | |
1308 | # return |
|
1308 | # return | |
1309 | # |
|
1309 | # | |
1310 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) |
|
1310 | # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex) | |
1311 | # self.__pulseFound = True |
|
1311 | # self.__pulseFound = True | |
1312 | # self.__startIndex = indexFound |
|
1312 | # self.__startIndex = indexFound | |
1313 | # |
|
1313 | # | |
1314 | # #If pulse was found ... |
|
1314 | # #If pulse was found ... | |
1315 | # for thisChannel in range(self.__nChannels): |
|
1315 | # for thisChannel in range(self.__nChannels): | |
1316 | # bufferByChannel = self.__bufferList[thisChannel] |
|
1316 | # bufferByChannel = self.__bufferList[thisChannel] | |
1317 | # #print self.__startIndex |
|
1317 | # #print self.__startIndex | |
1318 | # x = numpy.array(bufferByChannel) |
|
1318 | # x = numpy.array(bufferByChannel) | |
1319 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] |
|
1319 | # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples] | |
1320 | # |
|
1320 | # | |
1321 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1321 | # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1322 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight |
|
1322 | # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight | |
1323 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 |
|
1323 | # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6 | |
1324 | # |
|
1324 | # | |
1325 | # dataOut.data = self.__arrayBuffer |
|
1325 | # dataOut.data = self.__arrayBuffer | |
1326 | # |
|
1326 | # | |
1327 | # self.__startIndex += self.__newNSamples |
|
1327 | # self.__startIndex += self.__newNSamples | |
1328 | # |
|
1328 | # | |
1329 | # return |
|
1329 | # return |
General Comments 0
You need to be logged in to leave comments.
Login now