@@ -1150,7 +1150,7 class Parameters(JROData): | |||||
1150 |
|
1150 | |||
1151 | self.type = "Parameters" |
|
1151 | self.type = "Parameters" | |
1152 |
|
1152 | |||
1153 | def getTimeRange1(self): |
|
1153 | def getTimeRange1(self, interval): | |
1154 |
|
1154 | |||
1155 | datatime = [] |
|
1155 | datatime = [] | |
1156 |
|
1156 | |||
@@ -1162,7 +1162,7 class Parameters(JROData): | |||||
1162 | # datatime.append(self.utctimeInit) |
|
1162 | # datatime.append(self.utctimeInit) | |
1163 | # datatime.append(self.utctimeInit + self.outputInterval) |
|
1163 | # datatime.append(self.utctimeInit + self.outputInterval) | |
1164 | datatime.append(time1) |
|
1164 | datatime.append(time1) | |
1165 |
datatime.append(time1 + |
|
1165 | datatime.append(time1 + interval) | |
1166 |
|
1166 | |||
1167 | datatime = numpy.array(datatime) |
|
1167 | datatime = numpy.array(datatime) | |
1168 |
|
1168 |
@@ -251,7 +251,7 class SkyMapPlot(Figure): | |||||
251 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
251 | self.addAxes(1, 1, 0, 0, 1, 1, True) | |
252 |
|
252 | |||
253 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
253 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, | |
254 |
tmin= |
|
254 | tmin=0, tmax=24, timerange=None, | |
255 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
255 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
256 | server=None, folder=None, username=None, password=None, |
|
256 | server=None, folder=None, username=None, password=None, | |
257 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
257 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
@@ -272,19 +272,19 class SkyMapPlot(Figure): | |||||
272 | zmax : None |
|
272 | zmax : None | |
273 | """ |
|
273 | """ | |
274 |
|
274 | |||
275 |
arrayParameters = dataOut.data_param |
|
275 | arrayParameters = dataOut.data_param | |
276 | error = arrayParameters[:,-1] |
|
276 | error = arrayParameters[:,-1] | |
277 | indValid = numpy.where(error == 0)[0] |
|
277 | indValid = numpy.where(error == 0)[0] | |
278 | finalMeteor = arrayParameters[indValid,:] |
|
278 | finalMeteor = arrayParameters[indValid,:] | |
279 |
finalAzimuth = finalMeteor[:, |
|
279 | finalAzimuth = finalMeteor[:,3] | |
280 |
finalZenith = finalMeteor[:, |
|
280 | finalZenith = finalMeteor[:,4] | |
281 |
|
281 | |||
282 | x = finalAzimuth*numpy.pi/180 |
|
282 | x = finalAzimuth*numpy.pi/180 | |
283 | y = finalZenith |
|
283 | y = finalZenith | |
284 |
x1 = dataOut. |
|
284 | x1 = [dataOut.ltctime, dataOut.ltctime] | |
285 |
|
285 | |||
286 | #thisDatetime = dataOut.datatime |
|
286 | #thisDatetime = dataOut.datatime | |
287 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut. |
|
287 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) | |
288 | title = wintitle + " Parameters" |
|
288 | title = wintitle + " Parameters" | |
289 | xlabel = "Zonal Zenith Angle (deg) " |
|
289 | xlabel = "Zonal Zenith Angle (deg) " | |
290 | ylabel = "Meridional Zenith Angle (deg)" |
|
290 | ylabel = "Meridional Zenith Angle (deg)" | |
@@ -439,22 +439,13 class WindProfilerPlot(Figure): | |||||
439 | zmax : None |
|
439 | zmax : None | |
440 | """ |
|
440 | """ | |
441 |
|
441 | |||
442 | if channelList == None: |
|
|||
443 | channelIndexList = dataOut.channelIndexList |
|
|||
444 | else: |
|
|||
445 | channelIndexList = [] |
|
|||
446 | for channel in channelList: |
|
|||
447 | if channel not in dataOut.channelList: |
|
|||
448 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
|||
449 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
|||
450 |
|
||||
451 | # if timerange is not None: |
|
442 | # if timerange is not None: | |
452 | # self.timerange = timerange |
|
443 | # self.timerange = timerange | |
453 | # |
|
444 | # | |
454 | # tmin = None |
|
445 | # tmin = None | |
455 | # tmax = None |
|
446 | # tmax = None | |
456 |
|
447 | |||
457 | x = dataOut.getTimeRange1() |
|
448 | x = dataOut.getTimeRange1(dataOut.outputInterval) | |
458 | # y = dataOut.heightList |
|
449 | # y = dataOut.heightList | |
459 | y = dataOut.heightList |
|
450 | y = dataOut.heightList | |
460 |
|
451 | |||
@@ -480,7 +471,7 class WindProfilerPlot(Figure): | |||||
480 |
|
471 | |||
481 | # showprofile = False |
|
472 | # showprofile = False | |
482 | # thisDatetime = dataOut.datatime |
|
473 | # thisDatetime = dataOut.datatime | |
483 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut. |
|
474 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) | |
484 | title = wintitle + "Wind" |
|
475 | title = wintitle + "Wind" | |
485 | xlabel = "" |
|
476 | xlabel = "" | |
486 | ylabel = "Range (Km)" |
|
477 | ylabel = "Range (Km)" | |
@@ -707,7 +698,7 class ParametersPlot(Figure): | |||||
707 | if parameterIndex == None: |
|
698 | if parameterIndex == None: | |
708 | parameterIndex = 1 |
|
699 | parameterIndex = 1 | |
709 |
|
700 | |||
710 | x = dataOut.getTimeRange1() |
|
701 | x = dataOut.getTimeRange1(dataOut.paramInterval) | |
711 | y = dataOut.heightList |
|
702 | y = dataOut.heightList | |
712 | z = data_param[channelIndexList,parameterIndex,:].copy() |
|
703 | z = data_param[channelIndexList,parameterIndex,:].copy() | |
713 |
|
704 | |||
@@ -1100,7 +1091,7 class EWDriftsPlot(Figure): | |||||
1100 | tmin = None |
|
1091 | tmin = None | |
1101 | tmax = None |
|
1092 | tmax = None | |
1102 |
|
1093 | |||
1103 | x = dataOut.getTimeRange1() |
|
1094 | x = dataOut.getTimeRange1(dataOut.outputInterval) | |
1104 | # y = dataOut.heightList |
|
1095 | # y = dataOut.heightList | |
1105 | y = dataOut.heightList |
|
1096 | y = dataOut.heightList | |
1106 |
|
1097 | |||
@@ -1280,7 +1271,7 class PhasePlot(Figure): | |||||
1280 |
|
1271 | |||
1281 | tmin = None |
|
1272 | tmin = None | |
1282 | tmax = None |
|
1273 | tmax = None | |
1283 | x = dataOut.getTimeRange1() |
|
1274 | x = dataOut.getTimeRange1(dataOut.outputInterval) | |
1284 | y = dataOut.getHeiRange() |
|
1275 | y = dataOut.getHeiRange() | |
1285 |
|
1276 | |||
1286 |
|
1277 |
This diff has been collapsed as it changes many lines, (650 lines changed) Show them Hide them | |||||
@@ -3,13 +3,29 import time | |||||
3 | import os |
|
3 | import os | |
4 | import h5py |
|
4 | import h5py | |
5 | import re |
|
5 | import re | |
|
6 | import datetime | |||
6 |
|
7 | |||
7 | from schainpy.model.data.jrodata import * |
|
8 | from schainpy.model.data.jrodata import * | |
8 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
|
10 | # from jroIO_base import * | |||
9 | from schainpy.model.io.jroIO_base import * |
|
11 | from schainpy.model.io.jroIO_base import * | |
|
12 | import schainpy | |||
10 |
|
13 | |||
11 |
|
14 | |||
12 | class HDF5Reader(ProcessingUnit): |
|
15 | class HDF5Reader(ProcessingUnit): | |
|
16 | ''' | |||
|
17 | Reads HDF5 format files | |||
|
18 | ||||
|
19 | path | |||
|
20 | ||||
|
21 | startDate | |||
|
22 | ||||
|
23 | endDate | |||
|
24 | ||||
|
25 | startTime | |||
|
26 | ||||
|
27 | endTime | |||
|
28 | ''' | |||
13 |
|
29 | |||
14 | ext = ".hdf5" |
|
30 | ext = ".hdf5" | |
15 |
|
31 | |||
@@ -17,15 +33,19 class HDF5Reader(ProcessingUnit): | |||||
17 |
|
33 | |||
18 | timezone = None |
|
34 | timezone = None | |
19 |
|
35 | |||
20 |
s |
|
36 | startTime = None | |
21 |
|
37 | |||
22 |
|
|
38 | endTime = None | |
23 |
|
39 | |||
24 | fileIndex = None |
|
40 | fileIndex = None | |
25 |
|
41 | |||
26 | blockIndex = None |
|
42 | utcList = None #To select data in the utctime list | |
27 |
|
43 | |||
28 | blocksPerFile = None |
|
44 | blockList = None #List to blocks to be read from the file | |
|
45 | ||||
|
46 | blocksPerFile = None #Number of blocks to be read | |||
|
47 | ||||
|
48 | blockIndex = None | |||
29 |
|
49 | |||
30 | path = None |
|
50 | path = None | |
31 |
|
51 | |||
@@ -37,10 +57,6 class HDF5Reader(ProcessingUnit): | |||||
37 |
|
57 | |||
38 | #Hdf5 File |
|
58 | #Hdf5 File | |
39 |
|
59 | |||
40 | fpMetadata = None |
|
|||
41 |
|
||||
42 | pathMeta = None |
|
|||
43 |
|
||||
44 | listMetaname = None |
|
60 | listMetaname = None | |
45 |
|
61 | |||
46 | listMeta = None |
|
62 | listMeta = None | |
@@ -57,153 +73,80 class HDF5Reader(ProcessingUnit): | |||||
57 |
|
73 | |||
58 | dataOut = None |
|
74 | dataOut = None | |
59 |
|
75 | |||
60 | nRecords = None |
|
|||
61 |
|
||||
62 |
|
76 | |||
63 | def __init__(self): |
|
77 | def __init__(self): | |
64 |
self.dataOut = |
|
78 | self.dataOut = Parameters() | |
65 | return |
|
79 | return | |
66 |
|
80 | |||
67 | def __createObjByDefault(self): |
|
81 | def setup(self, **kwargs): | |
68 |
|
||||
69 | dataObj = Parameters() |
|
|||
70 |
|
||||
71 | return dataObj |
|
|||
72 |
|
||||
73 | def setup(self,path=None, |
|
|||
74 | startDate=None, |
|
|||
75 | endDate=None, |
|
|||
76 | startTime=datetime.time(0,0,0), |
|
|||
77 | endTime=datetime.time(23,59,59), |
|
|||
78 | walk=True, |
|
|||
79 | timezone='ut', |
|
|||
80 | all=0, |
|
|||
81 | online=False, |
|
|||
82 | ext=None): |
|
|||
83 |
|
82 | |||
84 | if ext==None: |
|
83 | path = kwargs['path'] | |
85 | ext = self.ext |
|
84 | startDate = kwargs['startDate'] | |
86 | self.timezone = timezone |
|
85 | endDate = kwargs['endDate'] | |
87 | # self.all = all |
|
86 | startTime = kwargs['startTime'] | |
88 | # self.online = online |
|
87 | endTime = kwargs['endTime'] | |
89 | self.path = path |
|
88 | walk = kwargs['walk'] | |
90 |
|
89 | if kwargs.has_key('ext'): | ||
91 | startDateTime = datetime.datetime.combine(startDate,startTime) |
|
90 | ext = kwargs['ext'] | |
92 | endDateTime = datetime.datetime.combine(endDate,endTime) |
|
|||
93 | secStart = (startDateTime-datetime.datetime(1970,1,1)).total_seconds() |
|
|||
94 | secEnd = (endDateTime-datetime.datetime(1970,1,1)).total_seconds() |
|
|||
95 |
|
||||
96 | self.secStart = secStart |
|
|||
97 | self.secEnd = secEnd |
|
|||
98 |
|
||||
99 | if not(online): |
|
|||
100 | #Busqueda de archivos offline |
|
|||
101 | self.__searchFilesOffline(path, startDate, endDate, ext, startTime, endTime, secStart, secEnd, walk) |
|
|||
102 | else: |
|
91 | else: | |
103 | self.__searchFilesOnline(path, walk) |
|
92 | ext = '.hdf5' | |
|
93 | ||||
|
94 | print "[Reading] Searching files in offline mode ..." | |||
|
95 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |||
|
96 | startTime=startTime, endTime=endTime, | |||
|
97 | ext=ext, walk=walk) | |||
104 |
|
98 | |||
105 |
if not( |
|
99 | if not(filenameList): | |
106 | print "There is no files into the folder: %s"%(path) |
|
100 | print "There is no files into the folder: %s"%(path) | |
107 | sys.exit(-1) |
|
101 | sys.exit(-1) | |
108 |
|
102 | |||
109 | # self.__getExpParameters() |
|
|||
110 |
|
||||
111 | self.fileIndex = -1 |
|
103 | self.fileIndex = -1 | |
112 |
|
104 | self.startTime = startTime | ||
113 | self.__setNextFileOffline() |
|
105 | self.endTime = endTime | |
114 |
|
106 | |||
115 | self.__readMetadata() |
|
107 | self.__readMetadata() | |
116 |
|
108 | |||
117 | self.blockIndex = 0 |
|
109 | self.__setNextFileOffline() | |
118 |
|
110 | |||
119 | return |
|
111 | return | |
120 |
|
112 | |||
121 |
def __searchFilesOff |
|
113 | def __searchFilesOffLine(self, | |
122 | path, |
|
114 | path, | |
123 | startDate, |
|
115 | startDate=None, | |
124 | endDate, |
|
116 | endDate=None, | |
125 | ext, |
|
|||
126 | startTime=datetime.time(0,0,0), |
|
117 | startTime=datetime.time(0,0,0), | |
127 | endTime=datetime.time(23,59,59), |
|
118 | endTime=datetime.time(23,59,59), | |
128 |
|
|
119 | ext='.hdf5', | |
129 | secEnd = numpy.inf, |
|
|||
130 | walk=True): |
|
120 | walk=True): | |
131 |
|
121 | |||
132 | # self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
122 | expLabel = '' | |
133 | # |
|
123 | self.filenameList = [] | |
134 | # self.__checkPath() |
|
124 | self.datetimeList = [] | |
135 | # |
|
|||
136 | # self.__findDataForDates() |
|
|||
137 | # |
|
|||
138 | # self.__selectDataForTimes() |
|
|||
139 | # |
|
|||
140 | # for i in range(len(self.filenameList)): |
|
|||
141 | # print "%s" %(self.filenameList[i]) |
|
|||
142 |
|
125 | |||
143 | pathList = [] |
|
126 | pathList = [] | |
144 |
|
127 | |||
145 | if not walk: |
|
128 | JRODataObj = JRODataReader() | |
146 | #pathList.append(path) |
|
129 | dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True) | |
147 | multi_path = path.split(',') |
|
|||
148 | for single_path in multi_path: |
|
|||
149 | pathList.append(single_path) |
|
|||
150 |
|
130 | |||
151 | else: |
|
131 | if dateList == []: | |
152 | #dirList = [] |
|
132 | print "[Reading] No *%s files in %s from %s to %s)"%(ext, path, | |
153 | multi_path = path.split(',') |
|
133 | datetime.datetime.combine(startDate,startTime).ctime(), | |
154 | for single_path in multi_path: |
|
134 | datetime.datetime.combine(endDate,endTime).ctime()) | |
155 | dirList = [] |
|
|||
156 | for thisPath in os.listdir(single_path): |
|
|||
157 | if not os.path.isdir(os.path.join(single_path,thisPath)): |
|
|||
158 | continue |
|
|||
159 | if not isDoyFolder(thisPath): |
|
|||
160 | continue |
|
|||
161 |
|
||||
162 | dirList.append(thisPath) |
|
|||
163 |
|
||||
164 | if not(dirList): |
|
|||
165 | return None, None |
|
|||
166 |
|
||||
167 | thisDate = startDate |
|
|||
168 |
|
135 | |||
169 | while(thisDate <= endDate): |
|
|||
170 | year = thisDate.timetuple().tm_year |
|
|||
171 | doy = thisDate.timetuple().tm_yday |
|
|||
172 |
|
||||
173 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
|||
174 | if len(matchlist) == 0: |
|
|||
175 | thisDate += datetime.timedelta(1) |
|
|||
176 | continue |
|
|||
177 | for match in matchlist: |
|
|||
178 | pathList.append(os.path.join(single_path,match)) |
|
|||
179 |
|
||||
180 | thisDate += datetime.timedelta(1) |
|
|||
181 |
|
||||
182 | if pathList == []: |
|
|||
183 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
|||
184 | return None, None |
|
136 | return None, None | |
185 |
|
137 | |||
186 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
138 | if len(dateList) > 1: | |
|
139 | print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate) | |||
|
140 | else: | |||
|
141 | print "[Reading] data was found for the date %s" %(dateList[0]) | |||
187 |
|
142 | |||
188 | filenameList = [] |
|
143 | filenameList = [] | |
189 | datetimeList = [] |
|
144 | datetimeList = [] | |
190 | pathDict = {} |
|
|||
191 | filenameList_to_sort = [] |
|
|||
192 |
|
||||
193 | for i in range(len(pathList)): |
|
|||
194 |
|
|
145 | ||
195 | thisPath = pathList[i] |
|
146 | #---------------------------------------------------------------------------------- | |
196 |
|
|
147 | ||
197 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
148 | for thisPath in pathList: | |
198 | fileList.sort() |
|
149 | # thisPath = pathList[pathDict[file]] | |
199 | pathDict.setdefault(fileList[0]) |
|
|||
200 | pathDict[fileList[0]] = i |
|
|||
201 | filenameList_to_sort.append(fileList[0]) |
|
|||
202 |
|
||||
203 | filenameList_to_sort.sort() |
|
|||
204 |
|
||||
205 | for file in filenameList_to_sort: |
|
|||
206 | thisPath = pathList[pathDict[file]] |
|
|||
207 |
|
150 | |||
208 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
151 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
209 | fileList.sort() |
|
152 | fileList.sort() | |
@@ -211,7 +154,11 class HDF5Reader(ProcessingUnit): | |||||
211 | for file in fileList: |
|
154 | for file in fileList: | |
212 |
|
155 | |||
213 | filename = os.path.join(thisPath,file) |
|
156 | filename = os.path.join(thisPath,file) | |
214 | thisDatetime = self.__isFileinThisTime(filename, secStart, secEnd) |
|
157 | ||
|
158 | if not isFileInDateRange(filename, startDate, endDate): | |||
|
159 | continue | |||
|
160 | ||||
|
161 | thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime) | |||
215 |
|
162 | |||
216 | if not(thisDatetime): |
|
163 | if not(thisDatetime): | |
217 | continue |
|
164 | continue | |
@@ -220,27 +167,32 class HDF5Reader(ProcessingUnit): | |||||
220 | datetimeList.append(thisDatetime) |
|
167 | datetimeList.append(thisDatetime) | |
221 |
|
168 | |||
222 | if not(filenameList): |
|
169 | if not(filenameList): | |
223 |
print "Any file was found |
|
170 | print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
224 | return None, None |
|
171 | return None, None | |
225 |
|
172 | |||
226 |
print "%d file(s) was(were) found |
|
173 | print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime) | |
227 |
|
174 | |||
228 |
|
175 | |||
229 | for i in range(len(filenameList)): |
|
176 | for i in range(len(filenameList)): | |
230 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
177 | print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) | |
231 |
|
178 | |||
232 | self.filenameList = filenameList |
|
179 | self.filenameList = filenameList | |
233 | self.datetimeList = datetimeList |
|
180 | self.datetimeList = datetimeList | |
234 |
|
181 | |||
235 | return pathList, filenameList |
|
182 | return pathList, filenameList | |
236 |
|
183 | |||
237 |
def __isFile |
|
184 | def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime): | |
|
185 | ||||
238 |
|
|
186 | """ | |
239 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
187 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
240 |
|
188 | |||
241 | Inputs: |
|
189 | Inputs: | |
242 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
190 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
243 |
|
191 | |||
|
192 | startDate : fecha inicial del rango seleccionado en formato datetime.date | |||
|
193 | ||||
|
194 | endDate : fecha final del rango seleccionado en formato datetime.date | |||
|
195 | ||||
244 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
196 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
245 |
|
197 | |||
246 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
198 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
@@ -256,40 +208,58 class HDF5Reader(ProcessingUnit): | |||||
256 | """ |
|
208 | """ | |
257 |
|
209 | |||
258 | try: |
|
210 | try: | |
259 |
|
|
211 | fp = h5py.File(filename,'r') | |
|
212 | grp1 = fp['Data'] | |||
|
213 | ||||
260 | except IOError: |
|
214 | except IOError: | |
261 | traceback.print_exc() |
|
215 | traceback.print_exc() | |
262 | raise IOError, "The file %s can't be opened" %(filename) |
|
216 | raise IOError, "The file %s can't be opened" %(filename) | |
263 |
|
217 | #chino rata | ||
264 | grp = fp['Data'] |
|
218 | #In case has utctime attribute | |
265 |
|
|
219 | grp2 = grp1['utctime'] | |
266 | time0 = timeAux[:][0].astype(numpy.float) #Time Vector |
|
220 | # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time | |
|
221 | thisUtcTime = grp2.value[0] | |||
267 |
|
222 | |||
268 | fp.close() |
|
223 | fp.close() | |
269 |
|
224 | |||
270 | if self.timezone == 'lt': |
|
225 | thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0]) | |
271 | time0 -= 5*3600 |
|
226 | thisDate = thisDatetime.date() | |
|
227 | thisTime = thisDatetime.time() | |||
272 |
|
|
228 | ||
273 | boolTimer = numpy.logical_and(time0 >= startSeconds,time0 < endSeconds) |
|
229 | startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds() | |
|
230 | endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds() | |||
274 |
|
231 | |||
275 | if not (numpy.any(boolTimer)): |
|
232 | #General case | |
276 | return None |
|
233 | # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o | |
|
234 | #-----------o----------------------------o----------- | |||
|
235 | # startTime endTime | |||
277 |
|
236 | |||
278 | thisDatetime = datetime.datetime.utcfromtimestamp(time0[0]) |
|
237 | if endTime >= startTime: | |
|
238 | thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime) | |||
|
239 | if numpy.any(thisUtcLog): #If there is one block between the hours mentioned | |||
279 | return thisDatetime |
|
240 | return thisDatetime | |
|
241 | return None | |||
280 |
|
242 | |||
281 | def __checkPath(self): |
|
243 | #If endTime < startTime then endTime belongs to the next day | |
282 | if os.path.exists(self.path): |
|
244 | #<<<<<<<<<<<o o>>>>>>>>>>> | |
283 | self.status = 1 |
|
245 | #-----------o----------------------------o----------- | |
284 | else: |
|
246 | # endTime startTime | |
285 | self.status = 0 |
|
|||
286 | print 'Path:%s does not exists'%self.path |
|
|||
287 |
|
|
247 | ||
288 | return |
|
248 | if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime): | |
|
249 | return None | |||
|
250 | ||||
|
251 | if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime): | |||
|
252 | return None | |||
|
253 | ||||
|
254 | if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime): | |||
|
255 | return None | |||
|
256 | ||||
|
257 | return thisDatetime | |||
289 |
|
258 | |||
290 | def __setNextFileOffline(self): |
|
259 | def __setNextFileOffline(self): | |
|
260 | ||||
|
261 | self.fileIndex += 1 | |||
291 | idFile = self.fileIndex |
|
262 | idFile = self.fileIndex | |
292 | idFile += 1 |
|
|||
293 |
|
263 | |||
294 | if not(idFile < len(self.filenameList)): |
|
264 | if not(idFile < len(self.filenameList)): | |
295 | print "No more Files" |
|
265 | print "No more Files" | |
@@ -299,42 +269,50 class HDF5Reader(ProcessingUnit): | |||||
299 |
|
269 | |||
300 | filePointer = h5py.File(filename,'r') |
|
270 | filePointer = h5py.File(filename,'r') | |
301 |
|
|
271 | ||
302 | self.flagIsNewFile = 1 |
|
|||
303 | self.fileIndex = idFile |
|
|||
304 | self.filename = filename |
|
272 | self.filename = filename | |
305 |
|
273 | |||
306 | self.fp = filePointer |
|
274 | self.fp = filePointer | |
307 |
|
275 | |||
308 | print "Setting the file: %s"%self.filename |
|
276 | print "Setting the file: %s"%self.filename | |
309 |
|
277 | |||
310 | self.__readMetadata() |
|
278 | # self.__readMetadata() | |
311 | self.__setBlockList() |
|
279 | self.__setBlockList() | |
|
280 | self.__readData() | |||
312 | # self.nRecords = self.fp['Data'].attrs['blocksPerFile'] |
|
281 | # self.nRecords = self.fp['Data'].attrs['blocksPerFile'] | |
313 | self.nRecords = self.fp['Data'].attrs['nRecords'] |
|
282 | # self.nRecords = self.fp['Data'].attrs['nRecords'] | |
314 | self.blockIndex = 0 |
|
283 | self.blockIndex = 0 | |
315 | return 1 |
|
284 | return 1 | |
316 |
|
285 | |||
317 | def __setBlockList(self): |
|
286 | def __setBlockList(self): | |
318 | ''' |
|
287 | ''' | |
|
288 | Selects the data within the times defined | |||
|
289 | ||||
319 | self.fp |
|
290 | self.fp | |
320 |
self.start |
|
291 | self.startTime | |
321 |
self.end |
|
292 | self.endTime | |
322 |
|
293 | |||
323 | self.blockList |
|
294 | self.blockList | |
324 | self.blocksPerFile |
|
295 | self.blocksPerFile | |
325 |
|
296 | |||
326 | ''' |
|
297 | ''' | |
327 |
f |
|
298 | fp = self.fp | |
328 |
s |
|
299 | startTime = self.startTime | |
329 |
|
|
300 | endTime = self.endTime | |
330 |
|
301 | |||
331 |
grp = f |
|
302 | grp = fp['Data'] | |
332 |
time |
|
303 | thisUtcTime = grp['utctime'].value.astype(numpy.float)[0] | |
333 |
|
304 | |||
334 | if self.timezone == 'lt': |
|
305 | if self.timezone == 'lt': | |
335 |
time |
|
306 | thisUtcTime -= 5*3600 | |
|
307 | ||||
|
308 | thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0]) | |||
|
309 | thisDate = thisDatetime.date() | |||
|
310 | thisTime = thisDatetime.time() | |||
|
311 | ||||
|
312 | startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |||
|
313 | endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds() | |||
336 |
|
314 | |||
337 |
ind = numpy.where(numpy.logical_and(time |
|
315 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] | |
338 |
|
316 | |||
339 | self.blockList = ind |
|
317 | self.blockList = ind | |
340 | self.blocksPerFile = len(ind) |
|
318 | self.blocksPerFile = len(ind) | |
@@ -343,6 +321,8 class HDF5Reader(ProcessingUnit): | |||||
343 |
|
321 | |||
344 | def __readMetadata(self): |
|
322 | def __readMetadata(self): | |
345 | ''' |
|
323 | ''' | |
|
324 | Reads Metadata | |||
|
325 | ||||
346 | self.pathMeta |
|
326 | self.pathMeta | |
347 |
|
327 | |||
348 | self.listShapes |
|
328 | self.listShapes | |
@@ -351,41 +331,46 class HDF5Reader(ProcessingUnit): | |||||
351 |
|
331 | |||
352 | ''' |
|
332 | ''' | |
353 |
|
333 | |||
354 | grp = self.fp['Data'] |
|
334 | # grp = self.fp['Data'] | |
355 | pathMeta = os.path.join(self.path, grp.attrs['metadata']) |
|
335 | # pathMeta = os.path.join(self.path, grp.attrs['metadata']) | |
|
336 | # | |||
|
337 | # if pathMeta == self.pathMeta: | |||
|
338 | # return | |||
|
339 | # else: | |||
|
340 | # self.pathMeta = pathMeta | |||
|
341 | # | |||
|
342 | # filePointer = h5py.File(self.pathMeta,'r') | |||
|
343 | # groupPointer = filePointer['Metadata'] | |||
356 |
|
344 | |||
357 | if pathMeta == self.pathMeta: |
|
345 | filename = self.filenameList[0] | |
358 | return |
|
346 | ||
359 | else: |
|
347 | fp = h5py.File(filename,'r') | |
360 | self.pathMeta = pathMeta |
|
|||
361 |
|
348 | |||
362 | filePointer = h5py.File(self.pathMeta,'r') |
|
349 | gp = fp['Metadata'] | |
363 | groupPointer = filePointer['Metadata'] |
|
|||
364 |
|
350 | |||
365 | listMetaname = [] |
|
351 | listMetaname = [] | |
366 | listMetadata = [] |
|
352 | listMetadata = [] | |
367 |
for item in g |
|
353 | for item in gp.items(): | |
368 | name = item[0] |
|
354 | name = item[0] | |
369 |
|
355 | |||
370 | if name=='array dimensions': |
|
356 | if name=='array dimensions': | |
371 |
table = g |
|
357 | table = gp[name][:] | |
372 | listShapes = {} |
|
358 | listShapes = {} | |
373 | for shapes in table: |
|
359 | for shapes in table: | |
374 | listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4]]) |
|
360 | listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]]) | |
375 | else: |
|
361 | else: | |
376 |
data = g |
|
362 | data = gp[name].value | |
377 | listMetaname.append(name) |
|
363 | listMetaname.append(name) | |
378 | listMetadata.append(data) |
|
364 | listMetadata.append(data) | |
379 |
|
365 | |||
380 | if name=='type': |
|
366 | # if name=='type': | |
381 | self.__initDataOut(data) |
|
367 | # self.__initDataOut(data) | |
382 |
|
||||
383 | filePointer.close() |
|
|||
384 |
|
368 | |||
385 | self.listShapes = listShapes |
|
369 | self.listShapes = listShapes | |
386 | self.listMetaname = listMetaname |
|
370 | self.listMetaname = listMetaname | |
387 | self.listMeta = listMetadata |
|
371 | self.listMeta = listMetadata | |
388 |
|
372 | |||
|
373 | fp.close() | |||
389 | return |
|
374 | return | |
390 |
|
375 | |||
391 | def __readData(self): |
|
376 | def __readData(self): | |
@@ -395,113 +380,115 class HDF5Reader(ProcessingUnit): | |||||
395 |
|
380 | |||
396 | for item in grp.items(): |
|
381 | for item in grp.items(): | |
397 | name = item[0] |
|
382 | name = item[0] | |
398 |
|
||||
399 | if name == 'time': |
|
|||
400 | listdataname.append('utctime') |
|
|||
401 | timeAux = grp[name].value.astype(numpy.float)[0] |
|
|||
402 | listdata.append(timeAux) |
|
|||
403 | continue |
|
|||
404 |
|
||||
405 | listdataname.append(name) |
|
383 | listdataname.append(name) | |
406 | array = self.__setDataArray(self.nRecords, grp[name],self.listShapes[name]) |
|
384 | ||
|
385 | array = self.__setDataArray(grp[name],self.listShapes[name]) | |||
407 | listdata.append(array) |
|
386 | listdata.append(array) | |
408 |
|
387 | |||
409 | self.listDataname = listdataname |
|
388 | self.listDataname = listdataname | |
410 | self.listData = listdata |
|
389 | self.listData = listdata | |
411 | return |
|
390 | return | |
412 |
|
391 | |||
413 |
def __setDataArray(self, |
|
392 | def __setDataArray(self, dataset, shapes): | |
414 |
|
393 | |||
415 |
n |
|
394 | nDims = shapes[0] | |
416 |
|
395 | |||
417 |
n |
|
396 | nDim2 = shapes[1] #Dimension 0 | |
418 |
|
397 | |||
419 |
n |
|
398 | nDim1 = shapes[2] #Dimension 1, number of Points or Parameters | |
420 |
|
|
399 | ||
421 | mode = shapes[3] |
|
400 | nDim0 = shapes[3] #Dimension 2, number of samples or ranges | |
422 |
|
401 | |||
423 | # if nPoints>1: |
|
402 | mode = shapes[4] #Mode of storing | |
424 | # arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples)) |
|
403 | ||
425 | # else: |
|
404 | blockList = self.blockList | |
426 | # arrayData = numpy.zeros((nRecords,nChannels,nSamples)) |
|
405 | ||
427 | # |
|
406 | blocksPerFile = self.blocksPerFile | |
428 | # chn = 'channel' |
|
407 | ||
429 | # |
|
408 | #Depending on what mode the data was stored | |
430 | # for i in range(nChannels): |
|
409 | # if mode == 0: #Divided in channels | |
431 | # |
|
410 | # strds = 'channel' | |
432 | # data = dataset[chn + str(i)].value |
|
411 | # nDatas = nDim2 | |
433 | # |
|
412 | # newShapes = (blocksPerFile,nDim1,nDim0) | |
434 | # if nPoints>1: |
|
413 | if mode == 1: #Divided in parameter | |
435 | # data = numpy.rollaxis(data,2) |
|
|||
436 | # |
|
|||
437 | # arrayData[:,i,:] = data |
|
|||
438 |
|
||||
439 | arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples)) |
|
|||
440 | doSqueeze = False |
|
|||
441 | if mode == 0: |
|
|||
442 | strds = 'channel' |
|
|||
443 | nDatas = nChannels |
|
|||
444 | newShapes = (nRecords,nPoints,nSamples) |
|
|||
445 | if nPoints == 1: |
|
|||
446 | doSqueeze = True |
|
|||
447 | axisSqueeze = 2 |
|
|||
448 | else: |
|
|||
449 | strds = 'param' |
|
414 | strds = 'param' | |
450 |
nDatas = n |
|
415 | nDatas = nDim1 | |
451 |
newShapes = ( |
|
416 | newShapes = (blocksPerFile,nDim2,nDim0) | |
452 | if nChannels == 1: |
|
417 | elif mode==2: #Concatenated in a table | |
453 | doSqueeze = True |
|
418 | strds = 'table0' | |
454 | axisSqueeze = 1 |
|
419 | arrayData = dataset[strds].value | |
|
420 | #Selecting part of the dataset | |||
|
421 | utctime = arrayData[:,0] | |||
|
422 | u, indices = numpy.unique(utctime, return_index=True) | |||
|
423 | ||||
|
424 | if blockList.size != indices.size: | |||
|
425 | indMin = indices[blockList[0]] | |||
|
426 | indMax = indices[blockList[-1] + 1] | |||
|
427 | arrayData = arrayData[indMin:indMax,:] | |||
|
428 | return arrayData | |||
455 |
|
|
429 | ||
456 | for i in range(nDatas): |
|
430 | #------- One dimension --------------- | |
|
431 | if nDims == 1: | |||
|
432 | arrayData = dataset.value.astype(numpy.float)[0][blockList] | |||
|
433 | ||||
|
434 | #------- Two dimensions ----------- | |||
|
435 | elif nDims == 2: | |||
|
436 | arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0)) | |||
|
437 | newShapes = (blocksPerFile,nDim0) | |||
|
438 | nDatas = nDim1 | |||
457 |
|
439 | |||
|
440 | for i in range(nDatas): | |||
458 | data = dataset[strds + str(i)].value |
|
441 | data = dataset[strds + str(i)].value | |
459 | data = data.reshape(newShapes) |
|
442 | arrayData[:,i,:] = data[blockList,:] | |
460 |
|
443 | |||
461 | if mode == 0: |
|
444 | #------- Three dimensions --------- | |
462 | arrayData[:,i,:,:] = data |
|
|||
463 |
|
|
445 | else: | |
464 | arrayData[:,:,i,:] = data |
|
446 | arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0)) | |
|
447 | for i in range(nDatas): | |||
465 |
|
448 | |||
466 | if doSqueeze: |
|
449 | data = dataset[strds + str(i)].value | |
467 | arrayData = numpy.squeeze(arrayData, axis=axisSqueeze) |
|
450 | data = data[blockList,:,:] | |
|
451 | data = data.reshape(newShapes) | |||
|
452 | # if mode == 0: | |||
|
453 | # arrayData[:,i,:,:] = data | |||
|
454 | # else: | |||
|
455 | arrayData[:,:,i,:] = data | |||
468 |
|
456 | |||
469 | return arrayData |
|
457 | return arrayData | |
470 |
|
458 | |||
471 | def __initDataOut(self, type): |
|
|||
472 |
|
||||
473 | # if type =='Parameters': |
|
|||
474 | # self.dataOut = Parameters() |
|
|||
475 | # elif type =='Spectra': |
|
|||
476 | # self.dataOut = Spectra() |
|
|||
477 | # elif type =='Voltage': |
|
|||
478 | # self.dataOut = Voltage() |
|
|||
479 | # elif type =='Correlation': |
|
|||
480 | # self.dataOut = Correlation() |
|
|||
481 |
|
||||
482 | return |
|
|||
483 |
|
||||
484 | def __setDataOut(self): |
|
459 | def __setDataOut(self): | |
485 | listMeta = self.listMeta |
|
460 | listMeta = self.listMeta | |
486 | listMetaname = self.listMetaname |
|
461 | listMetaname = self.listMetaname | |
487 | listDataname = self.listDataname |
|
462 | listDataname = self.listDataname | |
488 | listData = self.listData |
|
463 | listData = self.listData | |
|
464 | listShapes = self.listShapes | |||
489 |
|
465 | |||
490 | blockIndex = self.blockIndex |
|
466 | blockIndex = self.blockIndex | |
491 | blockList = self.blockList |
|
467 | # blockList = self.blockList | |
492 |
|
468 | |||
493 | for i in range(len(listMeta)): |
|
469 | for i in range(len(listMeta)): | |
494 | setattr(self.dataOut,listMetaname[i],listMeta[i]) |
|
470 | setattr(self.dataOut,listMetaname[i],listMeta[i]) | |
495 |
|
471 | |||
496 | for j in range(len(listData)): |
|
472 | for j in range(len(listData)): | |
497 | if listDataname[j]=='utctime': |
|
473 | nShapes = listShapes[listDataname[j]][0] | |
498 | # setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex]]) |
|
474 | mode = listShapes[listDataname[j]][4] | |
499 | setattr(self.dataOut,'utctimeInit',listData[j][blockList[blockIndex]]) |
|
475 | if nShapes == 1: | |
500 | continue |
|
476 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex]) | |
|
477 | elif nShapes > 1: | |||
|
478 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:]) | |||
|
479 | #Mode Meteors | |||
|
480 | elif mode ==2: | |||
|
481 | selectedData = self.__selectDataMode2(listData[j], blockIndex) | |||
|
482 | setattr(self.dataOut, listDataname[j], selectedData) | |||
|
483 | return | |||
501 |
|
484 | |||
502 | setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex],:]) |
|
485 | def __selectDataMode2(self, data, blockIndex): | |
|
486 | utctime = data[:,0] | |||
|
487 | aux, indices = numpy.unique(utctime, return_inverse=True) | |||
|
488 | selInd = numpy.where(indices == blockIndex)[0] | |||
|
489 | selData = data[selInd,:] | |||
503 |
|
490 | |||
504 |
return sel |
|
491 | return selData | |
505 |
|
492 | |||
506 | def getData(self): |
|
493 | def getData(self): | |
507 |
|
494 | |||
@@ -515,12 +502,10 class HDF5Reader(ProcessingUnit): | |||||
515 | self.dataOut.flagNoData = True |
|
502 | self.dataOut.flagNoData = True | |
516 | return 0 |
|
503 | return 0 | |
517 |
|
504 | |||
518 | # |
|
|||
519 | # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
505 | # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers | |
520 | # self.dataOut.flagNoData = True |
|
506 | # self.dataOut.flagNoData = True | |
521 | # return 0 |
|
507 | # return 0 | |
522 |
|
508 | # self.__readData() | ||
523 | self.__readData() |
|
|||
524 | self.__setDataOut() |
|
509 | self.__setDataOut() | |
525 | self.dataOut.flagNoData = False |
|
510 | self.dataOut.flagNoData = False | |
526 |
|
511 | |||
@@ -540,6 +525,21 class HDF5Reader(ProcessingUnit): | |||||
540 | return |
|
525 | return | |
541 |
|
526 | |||
542 | class HDF5Writer(Operation): |
|
527 | class HDF5Writer(Operation): | |
|
528 | ''' | |||
|
529 | HDF5 Writer, stores parameters data in HDF5 format files | |||
|
530 | ||||
|
531 | path: path where the files will be stored | |||
|
532 | ||||
|
533 | blocksPerFile: number of blocks that will be saved in per HDF5 format file | |||
|
534 | ||||
|
535 | mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors) | |||
|
536 | ||||
|
537 | metadataList: list of attributes that will be stored as metadata | |||
|
538 | ||||
|
539 | dataList: list of attributes that will be stores as data | |||
|
540 | ||||
|
541 | ''' | |||
|
542 | ||||
543 |
|
543 | |||
544 | ext = ".hdf5" |
|
544 | ext = ".hdf5" | |
545 |
|
545 | |||
@@ -605,9 +605,6 class HDF5Writer(Operation): | |||||
605 |
|
605 | |||
606 | self.path = kwargs['path'] |
|
606 | self.path = kwargs['path'] | |
607 |
|
607 | |||
608 | if kwargs.has_key('ext'): |
|
|||
609 | self.ext = kwargs['ext'] |
|
|||
610 |
|
||||
611 | if kwargs.has_key('blocksPerFile'): |
|
608 | if kwargs.has_key('blocksPerFile'): | |
612 | self.blocksPerFile = kwargs['blocksPerFile'] |
|
609 | self.blocksPerFile = kwargs['blocksPerFile'] | |
613 | else: |
|
610 | else: | |
@@ -625,7 +622,7 class HDF5Writer(Operation): | |||||
625 | if type(mode) == int: |
|
622 | if type(mode) == int: | |
626 | mode = numpy.zeros(len(self.dataList)) + mode |
|
623 | mode = numpy.zeros(len(self.dataList)) + mode | |
627 | else: |
|
624 | else: | |
628 |
mode = numpy. |
|
625 | mode = numpy.ones(len(self.dataList)) | |
629 |
|
626 | |||
630 | self.mode = mode |
|
627 | self.mode = mode | |
631 |
|
628 | |||
@@ -641,23 +638,40 class HDF5Writer(Operation): | |||||
641 |
|
638 | |||
642 | dataAux = getattr(self.dataOut, self.dataList[i]) |
|
639 | dataAux = getattr(self.dataOut, self.dataList[i]) | |
643 |
|
640 | |||
|
641 | #--------------------- Conditionals ------------------------ | |||
|
642 | #There is no data | |||
|
643 | if dataAux == None: | |||
|
644 | return 0 | |||
|
645 | ||||
|
646 | #Not array, just a number | |||
644 | if type(dataAux)==float or type(dataAux)==int: |
|
647 | if type(dataAux)==float or type(dataAux)==int: | |
645 | arrayDim[i,0] = 1 |
|
648 | arrayDim[i,0] = 1 | |
646 | else: |
|
649 | mode[i] = 0 | |
647 |
|
|
650 | ||
648 | if dataAux == None: |
|
651 | #Mode meteors | |
649 | return 0 |
|
652 | elif mode[i] == 2: | |
|
653 | arrayDim[i,3] = dataAux.shape[-1] | |||
|
654 | arrayDim[i,4] = mode[i] #Mode the data was stored | |||
650 |
|
|
655 | ||
651 | arrayDim0 = dataAux.shape |
|
656 | #All the rest | |
652 | arrayDim[i,0] = len(arrayDim0) |
|
657 | else: | |
653 | arrayDim[i,4] = mode[i] |
|
658 | arrayDim0 = dataAux.shape #Data dimensions | |
|
659 | arrayDim[i,0] = len(arrayDim0) #Number of array dimensions | |||
|
660 | arrayDim[i,4] = mode[i] #Mode the data was stored | |||
654 |
|
661 | |||
|
662 | # Three-dimension arrays | |||
655 | if len(arrayDim0) == 3: |
|
663 | if len(arrayDim0) == 3: | |
656 | arrayDim[i,1:-1] = numpy.array(arrayDim0) |
|
664 | arrayDim[i,1:-1] = numpy.array(arrayDim0) | |
|
665 | ||||
|
666 | # Two-dimension arrays | |||
657 | elif len(arrayDim0) == 2: |
|
667 | elif len(arrayDim0) == 2: | |
658 |
arrayDim[i,2:-1] = numpy.array(arrayDim0) |
|
668 | arrayDim[i,2:-1] = numpy.array(arrayDim0) | |
|
669 | ||||
|
670 | # One-dimension arrays | |||
659 | elif len(arrayDim0) == 1: |
|
671 | elif len(arrayDim0) == 1: | |
660 | arrayDim[i,3] = arrayDim0 |
|
672 | arrayDim[i,3] = arrayDim0 | |
|
673 | ||||
|
674 | # No array, just a number | |||
661 | elif len(arrayDim0) == 0: |
|
675 | elif len(arrayDim0) == 0: | |
662 | arrayDim[i,0] = 1 |
|
676 | arrayDim[i,0] = 1 | |
663 | arrayDim[i,3] = 1 |
|
677 | arrayDim[i,3] = 1 | |
@@ -816,6 +830,7 class HDF5Writer(Operation): | |||||
816 |
|
830 | |||
817 | for i in range(len(self.dataList)): |
|
831 | for i in range(len(self.dataList)): | |
818 |
|
832 | |||
|
833 | #One-dimension data | |||
819 | if nDims[i]==1: |
|
834 | if nDims[i]==1: | |
820 | # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20') |
|
835 | # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20') | |
821 | ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64) |
|
836 | ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64) | |
@@ -824,15 +839,25 class HDF5Writer(Operation): | |||||
824 | nDimsForDs.append(nDims[i]) |
|
839 | nDimsForDs.append(nDims[i]) | |
825 | else: |
|
840 | else: | |
826 |
|
841 | |||
827 |
|
|
842 | #Channel mode | |
828 |
|
|
843 | # if mode[i] == 0: | |
829 | nDatas[i] = self.arrayDim[i,1] |
|
844 | # strMode = "channel" | |
830 |
|
|
845 | # | |
|
846 | # #nDatas is the number of arrays per variable | |||
|
847 | # if nDims[i] == 1: | |||
|
848 | # nDatas[i] = self.arrayDim[i,1] | |||
|
849 | # elif nDims[i] == 2: | |||
|
850 | # nDatas[i] = self.arrayDim[i,2] | |||
|
851 | ||||
|
852 | #Parameters mode | |||
|
853 | if mode[i] == 1: | |||
831 | strMode = "param" |
|
854 | strMode = "param" | |
832 | nDatas[i] = self.arrayDim[i,2] |
|
855 | nDatas[i] = self.arrayDim[i,2] | |
833 |
|
|
856 | ||
834 |
|
|
857 | #Meteors mode | |
835 | nDatas[i] = self.arrayDim[i,2] |
|
858 | elif mode[i] == 2: | |
|
859 | strMode = "table" | |||
|
860 | nDatas[i] = 1 | |||
836 |
|
861 | |||
837 | grp0 = grp.create_group(self.dataList[i]) |
|
862 | grp0 = grp.create_group(self.dataList[i]) | |
838 |
|
863 | |||
@@ -841,43 +866,43 class HDF5Writer(Operation): | |||||
841 |
|
866 | |||
842 | if nDims[i] == 3: |
|
867 | if nDims[i] == 3: | |
843 | ds0 = grp0.create_dataset(tableName, (nDim1[i],nDim0[i],1) , data = numpy.zeros((nDim1[i],nDim0[i],1)) ,maxshape=(None,nDim0[i],None), chunks=True) |
|
868 | ds0 = grp0.create_dataset(tableName, (nDim1[i],nDim0[i],1) , data = numpy.zeros((nDim1[i],nDim0[i],1)) ,maxshape=(None,nDim0[i],None), chunks=True) | |
|
869 | ||||
844 | else: |
|
870 | else: | |
845 | ds0 = grp0.create_dataset(tableName, (1,nDim0[i]), data = numpy.zeros((1,nDim0[i])) , maxshape=(None,nDim0[i]), chunks=True) |
|
871 | ds0 = grp0.create_dataset(tableName, (1,nDim0[i]), data = numpy.zeros((1,nDim0[i])) , maxshape=(None,nDim0[i]), chunks=True) | |
846 |
|
872 | |||
847 | ds.append(ds0) |
|
873 | ds.append(ds0) | |
848 | data.append([]) |
|
874 | data.append([]) | |
849 | nDimsForDs.append(nDims[i]) |
|
875 | nDimsForDs.append(nDims[i]) | |
|
876 | ||||
|
877 | fp.flush() | |||
|
878 | fp.close() | |||
|
879 | ||||
850 | self.nDatas = nDatas |
|
880 | self.nDatas = nDatas | |
851 | self.nDims = nDims |
|
881 | self.nDims = nDims | |
852 | self.nDimsForDs = nDimsForDs |
|
882 | self.nDimsForDs = nDimsForDs | |
853 | #Saving variables |
|
883 | #Saving variables | |
854 | print 'Writing the file: %s'%filename |
|
884 | print 'Writing the file: %s'%filename | |
855 | self.filename = filename |
|
885 | self.filename = filename | |
856 | self.fp = fp |
|
886 | # self.fp = fp | |
857 | self.grp = grp |
|
887 | # self.grp = grp | |
858 | self.grp.attrs.modify('nRecords', 1) |
|
888 | # self.grp.attrs.modify('nRecords', 1) | |
859 | self.ds = ds |
|
889 | self.ds = ds | |
860 | self.data = data |
|
890 | self.data = data | |
861 |
|
891 | # | ||
862 | self.setFile = setFile |
|
892 | # self.setFile = setFile | |
863 | self.firsttime = True |
|
893 | self.firsttime = True | |
864 | self.blockIndex = 0 |
|
894 | self.blockIndex = 0 | |
865 | return |
|
895 | return | |
866 |
|
896 | |||
867 | def putData(self): |
|
897 | def putData(self): | |
868 |
|
898 | |||
869 | if not self.firsttime: |
|
|||
870 | self.readBlock() |
|
|||
871 |
|
||||
872 | if self.blockIndex == self.blocksPerFile or self.dateFlag(): |
|
899 | if self.blockIndex == self.blocksPerFile or self.dateFlag(): | |
873 |
|
||||
874 | self.setNextFile() |
|
900 | self.setNextFile() | |
875 |
|
901 | |||
876 | self.setBlock() |
|
902 | # if not self.firsttime: | |
877 |
self. |
|
903 | self.readBlock() | |
878 |
|
904 | self.setBlock() #Prepare data to be written | ||
879 | self.fp.flush() |
|
905 | self.writeBlock() #Write data | |
880 | self.fp.close() |
|
|||
881 |
|
906 | |||
882 | return |
|
907 | return | |
883 |
|
908 | |||
@@ -903,10 +928,12 class HDF5Writer(Operation): | |||||
903 | ds[ind] = ds0 |
|
928 | ds[ind] = ds0 | |
904 | ind += 1 |
|
929 | ind += 1 | |
905 | else: |
|
930 | else: | |
906 | if self.mode[i]==0: |
|
931 | # if self.mode[i] == 0: | |
907 | strMode = "channel" |
|
932 | # strMode = "channel" | |
908 |
|
|
933 | if self.mode[i] == 1: | |
909 | strMode = "param" |
|
934 | strMode = "param" | |
|
935 | elif self.mode[i] == 2: | |||
|
936 | strMode = "table" | |||
910 |
|
|
937 | ||
911 | grp0 = grp[self.dataList[i]] |
|
938 | grp0 = grp[self.dataList[i]] | |
912 |
|
939 | |||
@@ -916,7 +943,6 class HDF5Writer(Operation): | |||||
916 | ds[ind] = ds0 |
|
943 | ds[ind] = ds0 | |
917 | ind += 1 |
|
944 | ind += 1 | |
918 |
|
945 | |||
919 |
|
||||
920 | self.fp = fp |
|
946 | self.fp = fp | |
921 | self.grp = grp |
|
947 | self.grp = grp | |
922 | self.ds = ds |
|
948 | self.ds = ds | |
@@ -940,30 +966,22 class HDF5Writer(Operation): | |||||
940 | for i in range(len(self.dataList)): |
|
966 | for i in range(len(self.dataList)): | |
941 | dataAux = getattr(self.dataOut,self.dataList[i]) |
|
967 | dataAux = getattr(self.dataOut,self.dataList[i]) | |
942 |
|
968 | |||
943 | if nDims[i] == 1: |
|
969 | if nDims[i] == 1 or mode[i] == 2: | |
944 | # data[ind] = numpy.array([str(dataAux)]).reshape((1,1)) |
|
|||
945 | data[ind] = dataAux |
|
970 | data[ind] = dataAux | |
946 | # if not self.firsttime: |
|
|||
947 | # data[ind] = numpy.hstack((self.ds[ind][:], self.data[ind])) |
|
|||
948 | ind += 1 |
|
971 | ind += 1 | |
949 |
|
|
972 | ||
|
973 | elif nDims[i] == 2: | |||
950 | for j in range(int(nDatas[i])): |
|
974 | for j in range(int(nDatas[i])): | |
951 | if (mode[i] == 0) or (nDims[i] == 2): #In case division per channel or Dimensions is only 1 |
|
|||
952 |
|
|
975 | data[ind] = dataAux[j,:] | |
953 |
|
|
976 | ind += 1 | |
954 | data[ind] = dataAux[:,j,:] |
|
|||
955 |
|
||||
956 | # if nDims[i] == 3: |
|
|||
957 | # data[ind] = data[ind].reshape((data[ind].shape[0],data[ind].shape[1],1)) |
|
|||
958 |
|
||||
959 | # if not self.firsttime: |
|
|||
960 | # data[ind] = numpy.dstack((self.ds[ind][:], data[ind])) |
|
|||
961 |
|
|
977 | ||
|
978 | elif nDims[i] == 3: | |||
|
979 | for j in range(int(nDatas[i])): | |||
|
980 | # Extinct mode 0 | |||
|
981 | # if (mode[i] == 0): | |||
|
982 | # data[ind] = dataAux[j,:,:] | |||
962 | # else: |
|
983 | # else: | |
963 |
|
|
984 | data[ind] = dataAux[:,j,:] | |
964 |
|
||||
965 | # if not self.firsttime: |
|
|||
966 | # data[ind] = numpy.vstack((self.ds[ind][:], data[ind])) |
|
|||
967 | ind += 1 |
|
985 | ind += 1 | |
968 |
|
986 | |||
969 | self.data = data |
|
987 | self.data = data | |
@@ -974,6 +992,8 class HDF5Writer(Operation): | |||||
974 | Saves the block in the HDF5 file |
|
992 | Saves the block in the HDF5 file | |
975 | ''' |
|
993 | ''' | |
976 | for i in range(len(self.ds)): |
|
994 | for i in range(len(self.ds)): | |
|
995 | ||||
|
996 | # First time | |||
977 | if self.firsttime: |
|
997 | if self.firsttime: | |
978 | # self.ds[i].resize(self.data[i].shape) |
|
998 | # self.ds[i].resize(self.data[i].shape) | |
979 | # self.ds[i][self.blockIndex,:] = self.data[i] |
|
999 | # self.ds[i][self.blockIndex,:] = self.data[i] | |
@@ -984,28 +1004,36 class HDF5Writer(Operation): | |||||
984 | self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1)) |
|
1004 | self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1)) | |
985 |
|
|
1005 | ||
986 |
|
|
1006 | self.ds[i].resize(self.data[i].shape) | |
|
1007 | ||||
987 |
self.ds[i][:] = self.data[i] |
|
1008 | self.ds[i][:] = self.data[i] | |
988 | else: |
|
1009 | else: | |
989 | if self.nDimsForDs[i] == 1: |
|
1010 | ||
|
1011 | # From second time | |||
|
1012 | # Meteors! | |||
|
1013 | if self.mode[i] == 2: | |||
|
1014 | dataShape = self.data[i].shape | |||
|
1015 | dsShape = self.ds[i].shape | |||
|
1016 | self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1])) | |||
|
1017 | self.ds[i][dsShape[0]:,:] = self.data[i] | |||
|
1018 | # One dimension | |||
|
1019 | elif self.nDimsForDs[i] == 1: | |||
990 | self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1)) |
|
1020 | self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1)) | |
991 | self.ds[i][0,-1] = self.data[i] |
|
1021 | self.ds[i][0,-1] = self.data[i] | |
|
1022 | # Two dimension | |||
992 | elif self.nDimsForDs[i] == 2: |
|
1023 | elif self.nDimsForDs[i] == 2: | |
993 | self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1])) |
|
1024 | self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1])) | |
994 | self.ds[i][self.blockIndex,:] = self.data[i] |
|
1025 | self.ds[i][self.blockIndex,:] = self.data[i] | |
|
1026 | # Three dimensions | |||
995 | elif self.nDimsForDs[i] == 3: |
|
1027 | elif self.nDimsForDs[i] == 3: | |
996 |
|
||||
997 | dataShape = self.data[i].shape |
|
|||
998 | dsShape = self.ds[i].shape |
|
|||
999 |
|
||||
1000 | if dataShape[0]==dsShape[0]: |
|
|||
1001 |
|
|
1028 | self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1)) | |
1002 |
|
|
1029 | self.ds[i][:,:,-1] = self.data[i] | |
1003 | else: |
|
|||
1004 | self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1],self.ds[i].shape[2])) |
|
|||
1005 | self.ds[i][dsShape[0]:,:,0] = self.data[i] |
|
|||
1006 |
|
1030 | |||
1007 | self.blockIndex += 1 |
|
|||
1008 | self.firsttime = False |
|
1031 | self.firsttime = False | |
|
1032 | self.blockIndex += 1 | |||
|
1033 | ||||
|
1034 | #Close to save changes | |||
|
1035 | self.fp.flush() | |||
|
1036 | self.fp.close() | |||
1009 | return |
|
1037 | return | |
1010 |
|
1038 | |||
1011 | def run(self, dataOut, **kwargs): |
|
1039 | def run(self, dataOut, **kwargs): |
@@ -365,7 +365,7 class ParametersProc(ProcessingUnit): | |||||
365 | #------------------- Detect Meteors ------------------------------ |
|
365 | #------------------- Detect Meteors ------------------------------ | |
366 |
|
366 | |||
367 | def MeteorDetection(self, hei_ref = None, tauindex = 0, |
|
367 | def MeteorDetection(self, hei_ref = None, tauindex = 0, | |
368 |
predefinedPhaseShifts = None, centerReceiverIndex = 2, |
|
368 | predefinedPhaseShifts = None, centerReceiverIndex = 2, | |
369 | cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25, |
|
369 | cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25, | |
370 | noise_timeStep = 4, noise_multiple = 4, |
|
370 | noise_timeStep = 4, noise_multiple = 4, | |
371 | multDet_timeLimit = 1, multDet_rangeLimit = 3, |
|
371 | multDet_timeLimit = 1, multDet_rangeLimit = 3, | |
@@ -456,10 +456,10 class ParametersProc(ProcessingUnit): | |||||
456 | if predefinedPhaseShifts != None: |
|
456 | if predefinedPhaseShifts != None: | |
457 | hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180 |
|
457 | hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180 | |
458 |
|
458 | |||
459 | elif beaconPhaseShifts: |
|
459 | # elif beaconPhaseShifts: | |
460 | #get hardware phase shifts using beacon signal |
|
460 | # #get hardware phase shifts using beacon signal | |
461 | hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10) |
|
461 | # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10) | |
462 | hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0) |
|
462 | # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0) | |
463 |
|
463 | |||
464 | else: |
|
464 | else: | |
465 | hardwarePhaseShifts = numpy.zeros(5) |
|
465 | hardwarePhaseShifts = numpy.zeros(5) | |
@@ -529,6 +529,9 class ParametersProc(ProcessingUnit): | |||||
529 | listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist, self.dataOut.timeInterval) |
|
529 | listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist, self.dataOut.timeInterval) | |
530 |
|
530 | |||
531 | if len(listMeteors4) > 0: |
|
531 | if len(listMeteors4) > 0: | |
|
532 | #Setting New Array | |||
|
533 | date = self.dataOut.utctime | |||
|
534 | arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang) | |||
532 |
|
535 | |||
533 | pairsList = [] |
|
536 | pairsList = [] | |
534 | pairx = (0,3) |
|
537 | pairx = (0,3) | |
@@ -536,10 +539,6 class ParametersProc(ProcessingUnit): | |||||
536 | pairsList.append(pairx) |
|
539 | pairsList.append(pairx) | |
537 | pairsList.append(pairy) |
|
540 | pairsList.append(pairy) | |
538 |
|
541 | |||
539 | #Setting New Array |
|
|||
540 | date = repr(self.dataOut.datatime) |
|
|||
541 | arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang) |
|
|||
542 |
|
||||
543 | meteorOps = MeteorOperations() |
|
542 | meteorOps = MeteorOperations() | |
544 | jph = numpy.array([0,0,0,0]) |
|
543 | jph = numpy.array([0,0,0,0]) | |
545 | h = (hmin,hmax) |
|
544 | h = (hmin,hmax) | |
@@ -561,14 +560,30 class ParametersProc(ProcessingUnit): | |||||
561 | #********************* END OF PARAMETERS CALCULATION ************************** |
|
560 | #********************* END OF PARAMETERS CALCULATION ************************** | |
562 |
|
561 | |||
563 | #***************************+ PASS DATA TO NEXT STEP ********************** |
|
562 | #***************************+ PASS DATA TO NEXT STEP ********************** | |
564 | arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1])) |
|
563 | # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1])) | |
565 |
self.dataOut.data_param = array |
|
564 | self.dataOut.data_param = arrayParameters | |
566 |
|
565 | |||
567 |
if array |
|
566 | if arrayParameters == None: | |
568 | self.dataOut.flagNoData = True |
|
567 | self.dataOut.flagNoData = True | |
569 |
|
568 | |||
570 | return |
|
569 | return | |
571 |
|
570 | |||
|
571 | def correctMeteorPhases(self): | |||
|
572 | ||||
|
573 | arrayParameters = self.dataOut.data_param | |||
|
574 | pairsList = [] | |||
|
575 | pairx = (0,3) | |||
|
576 | pairy = (1,2) | |||
|
577 | pairsList.append(pairx) | |||
|
578 | pairsList.append(pairy) | |||
|
579 | ||||
|
580 | meteorOps = MeteorOperations() | |||
|
581 | jph = numpy.array([0,0,0,0]) | |||
|
582 | h = (hmin,hmax) | |||
|
583 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, jph) | |||
|
584 | self.dataOut.data_param = arrayParameters | |||
|
585 | return | |||
|
586 | ||||
572 | def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n): |
|
587 | def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n): | |
573 |
|
588 | |||
574 | minIndex = min(newheis[0]) |
|
589 | minIndex = min(newheis[0]) | |
@@ -1055,133 +1070,134 class ParametersProc(ProcessingUnit): | |||||
1055 | arrayParameters = numpy.zeros((len(listMeteors), 14)) |
|
1070 | arrayParameters = numpy.zeros((len(listMeteors), 14)) | |
1056 |
|
1071 | |||
1057 | #Date inclusion |
|
1072 | #Date inclusion | |
1058 | date = re.findall(r'\((.*?)\)', date) |
|
1073 | # date = re.findall(r'\((.*?)\)', date) | |
1059 | date = date[0].split(',') |
|
1074 | # date = date[0].split(',') | |
1060 | date = map(int, date) |
|
1075 | # date = map(int, date) | |
1061 |
|
1076 | # | ||
1062 | if len(date)<6: |
|
1077 | # if len(date)<6: | |
1063 | date.append(0) |
|
1078 | # date.append(0) | |
1064 |
|
1079 | # | ||
1065 | date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]] |
|
1080 | # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]] | |
1066 | arrayDate = numpy.tile(date, (len(listMeteors), 1)) |
|
1081 | # arrayDate = numpy.tile(date, (len(listMeteors), 1)) | |
|
1082 | arrayDate = numpy.tile(date, (len(listMeteors))) | |||
1067 |
|
1083 | |||
1068 | #Meteor array |
|
1084 | #Meteor array | |
1069 | # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)] |
|
1085 | # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)] | |
1070 | # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors)) |
|
1086 | # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors)) | |
1071 |
|
1087 | |||
1072 | #Parameters Array |
|
1088 | #Parameters Array | |
1073 |
arrayParameters[:, |
|
1089 | arrayParameters[:,0] = arrayDate #Date | |
1074 |
arrayParameters[:, |
|
1090 | arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range | |
1075 |
arrayParameters[:, |
|
1091 | arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error | |
1076 |
arrayParameters[:, |
|
1092 | arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases | |
1077 | arrayParameters[:,-1] = arrayMeteors[:,-1] #Error |
|
1093 | arrayParameters[:,-1] = arrayMeteors[:,-1] #Error | |
1078 |
|
1094 | |||
1079 |
|
1095 | |||
1080 | return arrayParameters |
|
1096 | return arrayParameters | |
1081 |
|
1097 | |||
1082 | def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth): |
|
1098 | # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth): | |
1083 |
|
1099 | # | ||
1084 | arrayAOA = numpy.zeros((phases.shape[0],3)) |
|
1100 | # arrayAOA = numpy.zeros((phases.shape[0],3)) | |
1085 | cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList) |
|
1101 | # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList) | |
1086 |
|
1102 | # | ||
1087 | arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) |
|
1103 | # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) | |
1088 | cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) |
|
1104 | # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) | |
1089 | arrayAOA[:,2] = cosDirError |
|
1105 | # arrayAOA[:,2] = cosDirError | |
1090 |
|
1106 | # | ||
1091 | azimuthAngle = arrayAOA[:,0] |
|
1107 | # azimuthAngle = arrayAOA[:,0] | |
1092 | zenithAngle = arrayAOA[:,1] |
|
1108 | # zenithAngle = arrayAOA[:,1] | |
1093 |
|
1109 | # | ||
1094 | #Setting Error |
|
1110 | # #Setting Error | |
1095 | #Number 3: AOA not fesible |
|
1111 | # #Number 3: AOA not fesible | |
1096 | indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] |
|
1112 | # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] | |
1097 | error[indInvalid] = 3 |
|
1113 | # error[indInvalid] = 3 | |
1098 | #Number 4: Large difference in AOAs obtained from different antenna baselines |
|
1114 | # #Number 4: Large difference in AOAs obtained from different antenna baselines | |
1099 | indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] |
|
1115 | # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] | |
1100 | error[indInvalid] = 4 |
|
1116 | # error[indInvalid] = 4 | |
1101 | return arrayAOA, error |
|
1117 | # return arrayAOA, error | |
1102 |
|
1118 | # | ||
1103 | def __getDirectionCosines(self, arrayPhase, pairsList): |
|
1119 | # def __getDirectionCosines(self, arrayPhase, pairsList): | |
1104 |
|
1120 | # | ||
1105 | #Initializing some variables |
|
1121 | # #Initializing some variables | |
1106 | ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi |
|
1122 | # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi | |
1107 | ang_aux = ang_aux.reshape(1,ang_aux.size) |
|
1123 | # ang_aux = ang_aux.reshape(1,ang_aux.size) | |
1108 |
|
1124 | # | ||
1109 | cosdir = numpy.zeros((arrayPhase.shape[0],2)) |
|
1125 | # cosdir = numpy.zeros((arrayPhase.shape[0],2)) | |
1110 | cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) |
|
1126 | # cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) | |
1111 |
|
1127 | # | ||
1112 |
|
1128 | # | ||
1113 | for i in range(2): |
|
1129 | # for i in range(2): | |
1114 | #First Estimation |
|
1130 | # #First Estimation | |
1115 | phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]] |
|
1131 | # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]] | |
1116 | #Dealias |
|
1132 | # #Dealias | |
1117 | indcsi = numpy.where(phi0_aux > numpy.pi) |
|
1133 | # indcsi = numpy.where(phi0_aux > numpy.pi) | |
1118 | phi0_aux[indcsi] -= 2*numpy.pi |
|
1134 | # phi0_aux[indcsi] -= 2*numpy.pi | |
1119 | indcsi = numpy.where(phi0_aux < -numpy.pi) |
|
1135 | # indcsi = numpy.where(phi0_aux < -numpy.pi) | |
1120 | phi0_aux[indcsi] += 2*numpy.pi |
|
1136 | # phi0_aux[indcsi] += 2*numpy.pi | |
1121 | #Direction Cosine 0 |
|
1137 | # #Direction Cosine 0 | |
1122 | cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5) |
|
1138 | # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5) | |
1123 |
|
1139 | # | ||
1124 | #Most-Accurate Second Estimation |
|
1140 | # #Most-Accurate Second Estimation | |
1125 | phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]] |
|
1141 | # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]] | |
1126 | phi1_aux = phi1_aux.reshape(phi1_aux.size,1) |
|
1142 | # phi1_aux = phi1_aux.reshape(phi1_aux.size,1) | |
1127 | #Direction Cosine 1 |
|
1143 | # #Direction Cosine 1 | |
1128 | cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5) |
|
1144 | # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5) | |
1129 |
|
1145 | # | ||
1130 | #Searching the correct Direction Cosine |
|
1146 | # #Searching the correct Direction Cosine | |
1131 | cosdir0_aux = cosdir0[:,i] |
|
1147 | # cosdir0_aux = cosdir0[:,i] | |
1132 | cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) |
|
1148 | # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) | |
1133 | #Minimum Distance |
|
1149 | # #Minimum Distance | |
1134 | cosDiff = (cosdir1 - cosdir0_aux)**2 |
|
1150 | # cosDiff = (cosdir1 - cosdir0_aux)**2 | |
1135 | indcos = cosDiff.argmin(axis = 1) |
|
1151 | # indcos = cosDiff.argmin(axis = 1) | |
1136 | #Saving Value obtained |
|
1152 | # #Saving Value obtained | |
1137 | cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] |
|
1153 | # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] | |
1138 |
|
1154 | # | ||
1139 | return cosdir0, cosdir |
|
1155 | # return cosdir0, cosdir | |
1140 |
|
1156 | # | ||
1141 | def __calculateAOA(self, cosdir, azimuth): |
|
1157 | # def __calculateAOA(self, cosdir, azimuth): | |
1142 | cosdirX = cosdir[:,0] |
|
1158 | # cosdirX = cosdir[:,0] | |
1143 | cosdirY = cosdir[:,1] |
|
1159 | # cosdirY = cosdir[:,1] | |
1144 |
|
1160 | # | ||
1145 | zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi |
|
1161 | # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi | |
1146 | azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east |
|
1162 | # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east | |
1147 | angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() |
|
1163 | # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() | |
1148 |
|
1164 | # | ||
1149 | return angles |
|
1165 | # return angles | |
1150 |
|
1166 | # | ||
1151 | def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): |
|
1167 | # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): | |
1152 |
|
1168 | # | ||
1153 | Ramb = 375 #Ramb = c/(2*PRF) |
|
1169 | # Ramb = 375 #Ramb = c/(2*PRF) | |
1154 | Re = 6371 #Earth Radius |
|
1170 | # Re = 6371 #Earth Radius | |
1155 | heights = numpy.zeros(Ranges.shape) |
|
1171 | # heights = numpy.zeros(Ranges.shape) | |
1156 |
|
1172 | # | ||
1157 | R_aux = numpy.array([0,1,2])*Ramb |
|
1173 | # R_aux = numpy.array([0,1,2])*Ramb | |
1158 | R_aux = R_aux.reshape(1,R_aux.size) |
|
1174 | # R_aux = R_aux.reshape(1,R_aux.size) | |
1159 |
|
1175 | # | ||
1160 | Ranges = Ranges.reshape(Ranges.size,1) |
|
1176 | # Ranges = Ranges.reshape(Ranges.size,1) | |
1161 |
|
1177 | # | ||
1162 | Ri = Ranges + R_aux |
|
1178 | # Ri = Ranges + R_aux | |
1163 | hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re |
|
1179 | # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re | |
1164 |
|
1180 | # | ||
1165 | #Check if there is a height between 70 and 110 km |
|
1181 | # #Check if there is a height between 70 and 110 km | |
1166 | h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) |
|
1182 | # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) | |
1167 | ind_h = numpy.where(h_bool == 1)[0] |
|
1183 | # ind_h = numpy.where(h_bool == 1)[0] | |
1168 |
|
1184 | # | ||
1169 | hCorr = hi[ind_h, :] |
|
1185 | # hCorr = hi[ind_h, :] | |
1170 | ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) |
|
1186 | # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) | |
1171 |
|
1187 | # | ||
1172 | hCorr = hi[ind_hCorr] |
|
1188 | # hCorr = hi[ind_hCorr] | |
1173 | heights[ind_h] = hCorr |
|
1189 | # heights[ind_h] = hCorr | |
1174 |
|
1190 | # | ||
1175 | #Setting Error |
|
1191 | # #Setting Error | |
1176 | #Number 13: Height unresolvable echo: not valid height within 70 to 110 km |
|
1192 | # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km | |
1177 | #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km |
|
1193 | # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km | |
1178 |
|
1194 | # | ||
1179 | indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] |
|
1195 | # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] | |
1180 | error[indInvalid2] = 14 |
|
1196 | # error[indInvalid2] = 14 | |
1181 | indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] |
|
1197 | # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] | |
1182 | error[indInvalid1] = 13 |
|
1198 | # error[indInvalid1] = 13 | |
1183 |
|
1199 | # | ||
1184 | return heights, error |
|
1200 | # return heights, error | |
1185 |
|
1201 | |||
1186 | def SpectralFitting(self, getSNR = True, path=None, file=None, groupList=None): |
|
1202 | def SpectralFitting(self, getSNR = True, path=None, file=None, groupList=None): | |
1187 |
|
1203 | |||
@@ -1322,7 +1338,6 class ParametersProc(ProcessingUnit): | |||||
1322 | return chisq |
|
1338 | return chisq | |
1323 |
|
1339 | |||
1324 |
|
1340 | |||
1325 |
|
||||
1326 | class WindProfiler(Operation): |
|
1341 | class WindProfiler(Operation): | |
1327 |
|
1342 | |||
1328 | __isConfig = False |
|
1343 | __isConfig = False | |
@@ -1600,11 +1615,11 class WindProfiler(Operation): | |||||
1600 | winds = numpy.zeros((2,nInt))*numpy.nan |
|
1615 | winds = numpy.zeros((2,nInt))*numpy.nan | |
1601 |
|
1616 | |||
1602 | #Filter errors |
|
1617 | #Filter errors | |
1603 |
error = numpy.where(arrayMeteor[ |
|
1618 | error = numpy.where(arrayMeteor[:,-1] == 0)[0] | |
1604 |
finalMeteor = arrayMeteor[ |
|
1619 | finalMeteor = arrayMeteor[error,:] | |
1605 |
|
1620 | |||
1606 | #Meteor Histogram |
|
1621 | #Meteor Histogram | |
1607 |
finalHeights = finalMeteor[:, |
|
1622 | finalHeights = finalMeteor[:,2] | |
1608 | hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax)) |
|
1623 | hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax)) | |
1609 | nMeteorsPerI = hist[0] |
|
1624 | nMeteorsPerI = hist[0] | |
1610 | heightPerI = hist[1] |
|
1625 | heightPerI = hist[1] | |
@@ -1625,9 +1640,9 class WindProfiler(Operation): | |||||
1625 | meteorAux = finalMeteor2[ind1:ind2,:] |
|
1640 | meteorAux = finalMeteor2[ind1:ind2,:] | |
1626 |
|
1641 | |||
1627 | if meteorAux.shape[0] >= meteorThresh: |
|
1642 | if meteorAux.shape[0] >= meteorThresh: | |
1628 |
vel = meteorAux[:, |
|
1643 | vel = meteorAux[:, 6] | |
1629 |
zen = meteorAux[:, |
|
1644 | zen = meteorAux[:, 4]*numpy.pi/180 | |
1630 |
azim = meteorAux[:, |
|
1645 | azim = meteorAux[:, 3]*numpy.pi/180 | |
1631 |
|
1646 | |||
1632 | n = numpy.cos(zen) |
|
1647 | n = numpy.cos(zen) | |
1633 | # m = (1 - n**2)/(1 - numpy.tan(azim)**2) |
|
1648 | # m = (1 - n**2)/(1 - numpy.tan(azim)**2) | |
@@ -1745,7 +1760,7 class WindProfiler(Operation): | |||||
1745 | self.__firstdata = copy.copy(dataOut) |
|
1760 | self.__firstdata = copy.copy(dataOut) | |
1746 |
|
1761 | |||
1747 | else: |
|
1762 | else: | |
1748 |
self.__buffer = numpy. |
|
1763 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) | |
1749 |
|
1764 | |||
1750 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
1765 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready | |
1751 |
|
1766 | |||
@@ -1996,13 +2011,13 class PhaseCalibration(Operation): | |||||
1996 | h = (hmin, hmax) |
|
2011 | h = (hmin, hmax) | |
1997 | pairsList = ((0,3),(1,2)) |
|
2012 | pairsList = ((0,3),(1,2)) | |
1998 |
|
2013 | |||
1999 |
meteorsArray = self.__buffer |
|
2014 | meteorsArray = self.__buffer | |
2000 | error = meteorsArray[:,-1] |
|
2015 | error = meteorsArray[:,-1] | |
2001 | boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14) |
|
2016 | boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14) | |
2002 | ind1 = numpy.where(boolError)[0] |
|
2017 | ind1 = numpy.where(boolError)[0] | |
2003 | meteorsArray = meteorsArray[ind1,:] |
|
2018 | meteorsArray = meteorsArray[ind1,:] | |
2004 | meteorsArray[:,-1] = 0 |
|
2019 | meteorsArray[:,-1] = 0 | |
2005 |
phases = meteorsArray[:, |
|
2020 | phases = meteorsArray[:,8:12] | |
2006 |
|
2021 | |||
2007 | #Calculate Gammas |
|
2022 | #Calculate Gammas | |
2008 | gammas = self.__getGammas(pairs, k, distances, phases) |
|
2023 | gammas = self.__getGammas(pairs, k, distances, phases) | |
@@ -2033,14 +2048,14 class MeteorOperations(): | |||||
2033 | #JONES ET AL. 1998 |
|
2048 | #JONES ET AL. 1998 | |
2034 | AOAthresh = numpy.pi/8 |
|
2049 | AOAthresh = numpy.pi/8 | |
2035 | error = arrayParameters[:,-1] |
|
2050 | error = arrayParameters[:,-1] | |
2036 |
phases = -arrayParameters[:, |
|
2051 | phases = -arrayParameters[:,8:12] + jph | |
2037 |
arrayParameters[:, |
|
2052 | arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, error, AOAthresh, azimuth) | |
2038 |
|
2053 | |||
2039 | #Calculate Heights (Error N 13 and 14) |
|
2054 | #Calculate Heights (Error N 13 and 14) | |
2040 | error = arrayParameters[:,-1] |
|
2055 | error = arrayParameters[:,-1] | |
2041 |
Ranges = arrayParameters[:, |
|
2056 | Ranges = arrayParameters[:,1] | |
2042 |
zenith = arrayParameters[:, |
|
2057 | zenith = arrayParameters[:,4] | |
2043 |
arrayParameters[:, |
|
2058 | arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax) | |
2044 |
|
2059 | |||
2045 | #----------------------- Get Final data ------------------------------------ |
|
2060 | #----------------------- Get Final data ------------------------------------ | |
2046 | # error = arrayParameters[:,-1] |
|
2061 | # error = arrayParameters[:,-1] |
General Comments 0
You need to be logged in to leave comments.
Login now