##// END OF EJS Templates
Multiprocessing for BLTR (all operations) working
George Yong -
r1185:3cc57dcc4bfb
parent child
Show More
@@ -1,369 +1,371
1 '''
1 '''
2 Created on Nov 9, 2016
2 Created on Nov 9, 2016
3
3
4 @author: roj- LouVD
4 @author: roj- LouVD
5 '''
5 '''
6
6
7
7
8 import os
8 import os
9 import sys
9 import sys
10 import time
10 import time
11 import glob
11 import glob
12 import datetime
12 import datetime
13
13
14 import numpy
14 import numpy
15
15
16 from schainpy.model.proc.jroproc_base import ProcessingUnit
16 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
17 from schainpy.model.data.jrodata import Parameters
17 from schainpy.model.data.jrodata import Parameters
18 from schainpy.model.io.jroIO_base import JRODataReader, isNumber
18 from schainpy.model.io.jroIO_base import JRODataReader, isNumber
19 from schainpy.utils import log
19 from schainpy.utils import log
20
20
21 FILE_HEADER_STRUCTURE = numpy.dtype([
21 FILE_HEADER_STRUCTURE = numpy.dtype([
22 ('FMN', '<u4'),
22 ('FMN', '<u4'),
23 ('nrec', '<u4'),
23 ('nrec', '<u4'),
24 ('fr_offset', '<u4'),
24 ('fr_offset', '<u4'),
25 ('id', '<u4'),
25 ('id', '<u4'),
26 ('site', 'u1', (32,))
26 ('site', 'u1', (32,))
27 ])
27 ])
28
28
29 REC_HEADER_STRUCTURE = numpy.dtype([
29 REC_HEADER_STRUCTURE = numpy.dtype([
30 ('rmn', '<u4'),
30 ('rmn', '<u4'),
31 ('rcounter', '<u4'),
31 ('rcounter', '<u4'),
32 ('nr_offset', '<u4'),
32 ('nr_offset', '<u4'),
33 ('tr_offset', '<u4'),
33 ('tr_offset', '<u4'),
34 ('time', '<u4'),
34 ('time', '<u4'),
35 ('time_msec', '<u4'),
35 ('time_msec', '<u4'),
36 ('tag', 'u1', (32,)),
36 ('tag', 'u1', (32,)),
37 ('comments', 'u1', (32,)),
37 ('comments', 'u1', (32,)),
38 ('lat', '<f4'),
38 ('lat', '<f4'),
39 ('lon', '<f4'),
39 ('lon', '<f4'),
40 ('gps_status', '<u4'),
40 ('gps_status', '<u4'),
41 ('freq', '<u4'),
41 ('freq', '<u4'),
42 ('freq0', '<u4'),
42 ('freq0', '<u4'),
43 ('nchan', '<u4'),
43 ('nchan', '<u4'),
44 ('delta_r', '<u4'),
44 ('delta_r', '<u4'),
45 ('nranges', '<u4'),
45 ('nranges', '<u4'),
46 ('r0', '<u4'),
46 ('r0', '<u4'),
47 ('prf', '<u4'),
47 ('prf', '<u4'),
48 ('ncoh', '<u4'),
48 ('ncoh', '<u4'),
49 ('npoints', '<u4'),
49 ('npoints', '<u4'),
50 ('polarization', '<i4'),
50 ('polarization', '<i4'),
51 ('rx_filter', '<u4'),
51 ('rx_filter', '<u4'),
52 ('nmodes', '<u4'),
52 ('nmodes', '<u4'),
53 ('dmode_index', '<u4'),
53 ('dmode_index', '<u4'),
54 ('dmode_rngcorr', '<u4'),
54 ('dmode_rngcorr', '<u4'),
55 ('nrxs', '<u4'),
55 ('nrxs', '<u4'),
56 ('acf_length', '<u4'),
56 ('acf_length', '<u4'),
57 ('acf_lags', '<u4'),
57 ('acf_lags', '<u4'),
58 ('sea_to_atmos', '<f4'),
58 ('sea_to_atmos', '<f4'),
59 ('sea_notch', '<u4'),
59 ('sea_notch', '<u4'),
60 ('lh_sea', '<u4'),
60 ('lh_sea', '<u4'),
61 ('hh_sea', '<u4'),
61 ('hh_sea', '<u4'),
62 ('nbins_sea', '<u4'),
62 ('nbins_sea', '<u4'),
63 ('min_snr', '<f4'),
63 ('min_snr', '<f4'),
64 ('min_cc', '<f4'),
64 ('min_cc', '<f4'),
65 ('max_time_diff', '<f4')
65 ('max_time_diff', '<f4')
66 ])
66 ])
67
67
68 DATA_STRUCTURE = numpy.dtype([
68 DATA_STRUCTURE = numpy.dtype([
69 ('range', '<u4'),
69 ('range', '<u4'),
70 ('status', '<u4'),
70 ('status', '<u4'),
71 ('zonal', '<f4'),
71 ('zonal', '<f4'),
72 ('meridional', '<f4'),
72 ('meridional', '<f4'),
73 ('vertical', '<f4'),
73 ('vertical', '<f4'),
74 ('zonal_a', '<f4'),
74 ('zonal_a', '<f4'),
75 ('meridional_a', '<f4'),
75 ('meridional_a', '<f4'),
76 ('corrected_fading', '<f4'), # seconds
76 ('corrected_fading', '<f4'), # seconds
77 ('uncorrected_fading', '<f4'), # seconds
77 ('uncorrected_fading', '<f4'), # seconds
78 ('time_diff', '<f4'),
78 ('time_diff', '<f4'),
79 ('major_axis', '<f4'),
79 ('major_axis', '<f4'),
80 ('axial_ratio', '<f4'),
80 ('axial_ratio', '<f4'),
81 ('orientation', '<f4'),
81 ('orientation', '<f4'),
82 ('sea_power', '<u4'),
82 ('sea_power', '<u4'),
83 ('sea_algorithm', '<u4')
83 ('sea_algorithm', '<u4')
84 ])
84 ])
85
85
86
86 @MPDecorator
87 class BLTRParamReader(JRODataReader, ProcessingUnit):
87 class BLTRParamReader(JRODataReader, ProcessingUnit):
88 '''
88 '''
89 Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files
89 Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files
90 '''
90 '''
91
91
92 ext = '.sswma'
92 ext = '.sswma'
93
93
94 def __init__(self, **kwargs):
94 def __init__(self):
95
95
96 ProcessingUnit.__init__(self, **kwargs)
96 ProcessingUnit.__init__(self)
97
97
98 self.dataOut = Parameters()
98 self.dataOut = Parameters()
99 self.counter_records = 0
99 self.counter_records = 0
100 self.flagNoMoreFiles = 0
100 self.flagNoMoreFiles = 0
101 self.isConfig = False
101 self.isConfig = False
102 self.filename = None
102 self.filename = None
103
103
104 def setup(self,
104 def setup(self,
105 path=None,
105 path=None,
106 startDate=None,
106 startDate=None,
107 endDate=None,
107 endDate=None,
108 ext=None,
108 ext=None,
109 startTime=datetime.time(0, 0, 0),
109 startTime=datetime.time(0, 0, 0),
110 endTime=datetime.time(23, 59, 59),
110 endTime=datetime.time(23, 59, 59),
111 timezone=0,
111 timezone=0,
112 status_value=0,
112 status_value=0,
113 **kwargs):
113 **kwargs):
114
114
115 self.path = path
115 self.path = path
116 self.startDate = startDate
116 self.startDate = startDate
117 self.endDate = endDate
117 self.endDate = endDate
118 self.startTime = startTime
118 self.startTime = startTime
119 self.endTime = endTime
119 self.endTime = endTime
120 self.status_value = status_value
120 self.status_value = status_value
121 self.datatime = datetime.datetime(1900,1,1)
121 self.datatime = datetime.datetime(1900,1,1)
122
122
123 if self.path is None:
123 if self.path is None:
124 raise ValueError("The path is not valid")
124 raise ValueError("The path is not valid")
125
125
126 if ext is None:
126 if ext is None:
127 ext = self.ext
127 ext = self.ext
128
128
129 self.search_files(self.path, startDate, endDate, ext)
129 self.search_files(self.path, startDate, endDate, ext)
130 self.timezone = timezone
130 self.timezone = timezone
131 self.fileIndex = 0
131 self.fileIndex = 0
132
132
133 if not self.fileList:
133 if not self.fileList:
134 raise Warning("There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % (
134 raise Warning("There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % (
135 path))
135 path))
136
136
137 self.setNextFile()
137 self.setNextFile()
138
138
139 def search_files(self, path, startDate, endDate, ext):
139 def search_files(self, path, startDate, endDate, ext):
140 '''
140 '''
141 Searching for BLTR rawdata file in path
141 Searching for BLTR rawdata file in path
142 Creating a list of file to proces included in [startDate,endDate]
142 Creating a list of file to proces included in [startDate,endDate]
143
143
144 Input:
144 Input:
145 path - Path to find BLTR rawdata files
145 path - Path to find BLTR rawdata files
146 startDate - Select file from this date
146 startDate - Select file from this date
147 enDate - Select file until this date
147 enDate - Select file until this date
148 ext - Extension of the file to read
148 ext - Extension of the file to read
149 '''
149 '''
150
150
151 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
151 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
152 foldercounter = 0
152 foldercounter = 0
153 fileList0 = glob.glob1(path, "*%s" % ext)
153 fileList0 = glob.glob1(path, "*%s" % ext)
154 fileList0.sort()
154 fileList0.sort()
155
155
156 self.fileList = []
156 self.fileList = []
157 self.dateFileList = []
157 self.dateFileList = []
158
158
159 for thisFile in fileList0:
159 for thisFile in fileList0:
160 year = thisFile[-14:-10]
160 year = thisFile[-14:-10]
161 if not isNumber(year):
161 if not isNumber(year):
162 continue
162 continue
163
163
164 month = thisFile[-10:-8]
164 month = thisFile[-10:-8]
165 if not isNumber(month):
165 if not isNumber(month):
166 continue
166 continue
167
167
168 day = thisFile[-8:-6]
168 day = thisFile[-8:-6]
169 if not isNumber(day):
169 if not isNumber(day):
170 continue
170 continue
171
171
172 year, month, day = int(year), int(month), int(day)
172 year, month, day = int(year), int(month), int(day)
173 dateFile = datetime.date(year, month, day)
173 dateFile = datetime.date(year, month, day)
174
174
175 if (startDate > dateFile) or (endDate < dateFile):
175 if (startDate > dateFile) or (endDate < dateFile):
176 continue
176 continue
177
177
178 self.fileList.append(thisFile)
178 self.fileList.append(thisFile)
179 self.dateFileList.append(dateFile)
179 self.dateFileList.append(dateFile)
180
180
181 return
181 return
182
182
183 def setNextFile(self):
183 def setNextFile(self):
184
184
185 file_id = self.fileIndex
185 file_id = self.fileIndex
186
186
187 if file_id == len(self.fileList):
187 if file_id == len(self.fileList):
188 log.success('No more files in the folder', 'BLTRParamReader')
188 log.success('No more files in the folder', 'BLTRParamReader')
189 self.flagNoMoreFiles = 1
189 self.flagNoMoreFiles = 1
190 return 0
190 return 0
191
191
192 log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader')
192 log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader')
193 filename = os.path.join(self.path, self.fileList[file_id])
193 filename = os.path.join(self.path, self.fileList[file_id])
194
194
195 dirname, name = os.path.split(filename)
195 dirname, name = os.path.split(filename)
196 # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya
196 # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya
197 self.siteFile = name.split('.')[0]
197 self.siteFile = name.split('.')[0]
198 if self.filename is not None:
198 if self.filename is not None:
199 self.fp.close()
199 self.fp.close()
200 self.filename = filename
200 self.filename = filename
201 self.fp = open(self.filename, 'rb')
201 self.fp = open(self.filename, 'rb')
202 self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1)
202 self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1)
203 self.nrecords = self.header_file['nrec'][0]
203 self.nrecords = self.header_file['nrec'][0]
204 self.sizeOfFile = os.path.getsize(self.filename)
204 self.sizeOfFile = os.path.getsize(self.filename)
205 self.counter_records = 0
205 self.counter_records = 0
206 self.flagIsNewFile = 0
206 self.flagIsNewFile = 0
207 self.fileIndex += 1
207 self.fileIndex += 1
208
208
209 return 1
209 return 1
210
210
211 def readNextBlock(self):
211 def readNextBlock(self):
212
212
213 while True:
213 while True:
214 if self.counter_records == self.nrecords:
214 if self.counter_records == self.nrecords:
215 self.flagIsNewFile = 1
215 self.flagIsNewFile = 1
216 if not self.setNextFile():
216 if not self.setNextFile():
217 return 0
217 return 0
218
218
219 self.readBlock()
219 self.readBlock()
220
220
221 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
221 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
222 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
222 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
223 log.warning(
223 log.warning(
224 'Reading Record No. {}/{} -> {} [Skipping]'.format(
224 'Reading Record No. {}/{} -> {} [Skipping]'.format(
225 self.counter_records,
225 self.counter_records,
226 self.nrecords,
226 self.nrecords,
227 self.datatime.ctime()),
227 self.datatime.ctime()),
228 'BLTRParamReader')
228 'BLTRParamReader')
229 continue
229 continue
230 break
230 break
231
231
232 log.log('Reading Record No. {}/{} -> {}'.format(
232 log.log('Reading Record No. {}/{} -> {}'.format(
233 self.counter_records,
233 self.counter_records,
234 self.nrecords,
234 self.nrecords,
235 self.datatime.ctime()), 'BLTRParamReader')
235 self.datatime.ctime()), 'BLTRParamReader')
236
236
237 return 1
237 return 1
238
238
239 def readBlock(self):
239 def readBlock(self):
240
240
241 pointer = self.fp.tell()
241 pointer = self.fp.tell()
242 header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1)
242 header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1)
243 self.nchannels = header_rec['nchan'][0] / 2
243 self.nchannels = header_rec['nchan'][0] / 2
244 self.kchan = header_rec['nrxs'][0]
244 self.kchan = header_rec['nrxs'][0]
245 self.nmodes = header_rec['nmodes'][0]
245 self.nmodes = header_rec['nmodes'][0]
246 self.nranges = header_rec['nranges'][0]
246 self.nranges = header_rec['nranges'][0]
247 self.fp.seek(pointer)
247 self.fp.seek(pointer)
248 self.height = numpy.empty((self.nmodes, self.nranges))
248 self.height = numpy.empty((self.nmodes, self.nranges))
249 self.snr = numpy.empty((self.nmodes, self.nchannels, self.nranges))
249 self.snr = numpy.empty((self.nmodes, int(self.nchannels), self.nranges))
250 self.buffer = numpy.empty((self.nmodes, 3, self.nranges))
250 self.buffer = numpy.empty((self.nmodes, 3, self.nranges))
251 self.flagDiscontinuousBlock = 0
251 self.flagDiscontinuousBlock = 0
252
252
253 for mode in range(self.nmodes):
253 for mode in range(self.nmodes):
254 self.readHeader()
254 self.readHeader()
255 data = self.readData()
255 data = self.readData()
256 self.height[mode] = (data[0] - self.correction) / 1000.
256 self.height[mode] = (data[0] - self.correction) / 1000.
257 self.buffer[mode] = data[1]
257 self.buffer[mode] = data[1]
258 self.snr[mode] = data[2]
258 self.snr[mode] = data[2]
259
259
260 self.counter_records = self.counter_records + self.nmodes
260 self.counter_records = self.counter_records + self.nmodes
261
261
262 return
262 return
263
263
264 def readHeader(self):
264 def readHeader(self):
265 '''
265 '''
266 RecordHeader of BLTR rawdata file
266 RecordHeader of BLTR rawdata file
267 '''
267 '''
268
268
269 header_structure = numpy.dtype(
269 header_structure = numpy.dtype(
270 REC_HEADER_STRUCTURE.descr + [
270 REC_HEADER_STRUCTURE.descr + [
271 ('antenna_coord', 'f4', (2, self.nchannels)),
271 ('antenna_coord', 'f4', (2, int(self.nchannels))),
272 ('rx_gains', 'u4', (self.nchannels,)),
272 ('rx_gains', 'u4', (int(self.nchannels),)),
273 ('rx_analysis', 'u4', (self.nchannels,))
273 ('rx_analysis', 'u4', (int(self.nchannels),))
274 ]
274 ]
275 )
275 )
276
276
277 self.header_rec = numpy.fromfile(self.fp, header_structure, 1)
277 self.header_rec = numpy.fromfile(self.fp, header_structure, 1)
278 self.lat = self.header_rec['lat'][0]
278 self.lat = self.header_rec['lat'][0]
279 self.lon = self.header_rec['lon'][0]
279 self.lon = self.header_rec['lon'][0]
280 self.delta = self.header_rec['delta_r'][0]
280 self.delta = self.header_rec['delta_r'][0]
281 self.correction = self.header_rec['dmode_rngcorr'][0]
281 self.correction = self.header_rec['dmode_rngcorr'][0]
282 self.imode = self.header_rec['dmode_index'][0]
282 self.imode = self.header_rec['dmode_index'][0]
283 self.antenna = self.header_rec['antenna_coord']
283 self.antenna = self.header_rec['antenna_coord']
284 self.rx_gains = self.header_rec['rx_gains']
284 self.rx_gains = self.header_rec['rx_gains']
285 self.time = self.header_rec['time'][0]
285 self.time = self.header_rec['time'][0]
286 dt = datetime.datetime.utcfromtimestamp(self.time)
286 dt = datetime.datetime.utcfromtimestamp(self.time)
287 if dt.date()>self.datatime.date():
287 if dt.date()>self.datatime.date():
288 self.flagDiscontinuousBlock = 1
288 self.flagDiscontinuousBlock = 1
289 self.datatime = dt
289 self.datatime = dt
290
290
291 def readData(self):
291 def readData(self):
292 '''
292 '''
293 Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value.
293 Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value.
294
294
295 Input:
295 Input:
296 status_value - Array data is set to NAN for values that are not equal to status_value
296 status_value - Array data is set to NAN for values that are not equal to status_value
297
297
298 '''
298 '''
299 self.nchannels = int(self.nchannels)
299
300
300 data_structure = numpy.dtype(
301 data_structure = numpy.dtype(
301 DATA_STRUCTURE.descr + [
302 DATA_STRUCTURE.descr + [
302 ('rx_saturation', 'u4', (self.nchannels,)),
303 ('rx_saturation', 'u4', (self.nchannels,)),
303 ('chan_offset', 'u4', (2 * self.nchannels,)),
304 ('chan_offset', 'u4', (2 * self.nchannels,)),
304 ('rx_amp', 'u4', (self.nchannels,)),
305 ('rx_amp', 'u4', (self.nchannels,)),
305 ('rx_snr', 'f4', (self.nchannels,)),
306 ('rx_snr', 'f4', (self.nchannels,)),
306 ('cross_snr', 'f4', (self.kchan,)),
307 ('cross_snr', 'f4', (self.kchan,)),
307 ('sea_power_relative', 'f4', (self.kchan,))]
308 ('sea_power_relative', 'f4', (self.kchan,))]
308 )
309 )
309
310
310 data = numpy.fromfile(self.fp, data_structure, self.nranges)
311 data = numpy.fromfile(self.fp, data_structure, self.nranges)
311
312
312 height = data['range']
313 height = data['range']
313 winds = numpy.array(
314 winds = numpy.array(
314 (data['zonal'], data['meridional'], data['vertical']))
315 (data['zonal'], data['meridional'], data['vertical']))
315 snr = data['rx_snr'].T
316 snr = data['rx_snr'].T
316
317
317 winds[numpy.where(winds == -9999.)] = numpy.nan
318 winds[numpy.where(winds == -9999.)] = numpy.nan
318 winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
319 winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
319 snr[numpy.where(snr == -9999.)] = numpy.nan
320 snr[numpy.where(snr == -9999.)] = numpy.nan
320 snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
321 snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
321 snr = numpy.power(10, snr / 10)
322 snr = numpy.power(10, snr / 10)
322
323
323 return height, winds, snr
324 return height, winds, snr
324
325
325 def set_output(self):
326 def set_output(self):
326 '''
327 '''
327 Storing data from databuffer to dataOut object
328 Storing data from databuffer to dataOut object
328 '''
329 '''
329
330
330 self.dataOut.data_SNR = self.snr
331 self.dataOut.data_SNR = self.snr
331 self.dataOut.height = self.height
332 self.dataOut.height = self.height
332 self.dataOut.data = self.buffer
333 self.dataOut.data = self.buffer
333 self.dataOut.utctimeInit = self.time
334 self.dataOut.utctimeInit = self.time
334 self.dataOut.utctime = self.dataOut.utctimeInit
335 self.dataOut.utctime = self.dataOut.utctimeInit
335 self.dataOut.useLocalTime = False
336 self.dataOut.useLocalTime = False
336 self.dataOut.paramInterval = 157
337 self.dataOut.paramInterval = 157
337 self.dataOut.timezone = self.timezone
338 self.dataOut.timezone = self.timezone
338 self.dataOut.site = self.siteFile
339 self.dataOut.site = self.siteFile
339 self.dataOut.nrecords = self.nrecords / self.nmodes
340 self.dataOut.nrecords = self.nrecords / self.nmodes
340 self.dataOut.sizeOfFile = self.sizeOfFile
341 self.dataOut.sizeOfFile = self.sizeOfFile
341 self.dataOut.lat = self.lat
342 self.dataOut.lat = self.lat
342 self.dataOut.lon = self.lon
343 self.dataOut.lon = self.lon
343 self.dataOut.channelList = list(range(self.nchannels))
344 self.dataOut.channelList = list(range(self.nchannels))
344 self.dataOut.kchan = self.kchan
345 self.dataOut.kchan = self.kchan
345 self.dataOut.delta = self.delta
346 self.dataOut.delta = self.delta
346 self.dataOut.correction = self.correction
347 self.dataOut.correction = self.correction
347 self.dataOut.nmodes = self.nmodes
348 self.dataOut.nmodes = self.nmodes
348 self.dataOut.imode = self.imode
349 self.dataOut.imode = self.imode
349 self.dataOut.antenna = self.antenna
350 self.dataOut.antenna = self.antenna
350 self.dataOut.rx_gains = self.rx_gains
351 self.dataOut.rx_gains = self.rx_gains
351 self.dataOut.flagNoData = False
352 self.dataOut.flagNoData = False
352 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
353 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
353
354
354 def getData(self):
355 def getData(self):
355 '''
356 '''
356 Storing data from databuffer to dataOut object
357 Storing data from databuffer to dataOut object
357 '''
358 '''
358 if self.flagNoMoreFiles:
359 if self.flagNoMoreFiles:
359 self.dataOut.flagNoData = True
360 self.dataOut.flagNoData = True
360 log.success('No file left to process', 'BLTRParamReader')
361 log.success('No file left to process', 'BLTRParamReader')
361 return 0
362 return 0
362
363
363 if not self.readNextBlock():
364 if not self.readNextBlock():
364 self.dataOut.flagNoData = True
365 self.dataOut.flagNoData = True
365 return 0
366 return 0
366
367
367 self.set_output()
368 self.set_output()
368
369
369 return 1 No newline at end of file
370 return 1
371 No newline at end of file
@@ -1,402 +1,406
1 '''
1 '''
2 Created on Oct 24, 2016
2 Created on Oct 24, 2016
3
3
4 @author: roj- LouVD
4 @author: roj- LouVD
5 '''
5 '''
6
6
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10 import time
10 import time
11 from time import gmtime
11 from time import gmtime
12
12
13 from numpy import transpose
13 from numpy import transpose
14
14
15 from .jroproc_base import ProcessingUnit, Operation
15 from .jroproc_base import ProcessingUnit, MPDecorator, Operation
16 from schainpy.model.data.jrodata import Parameters
16 from schainpy.model.data.jrodata import Parameters
17
17
18 @MPDecorator
19 class BLTRParametersProc(ProcessingUnit):
18
20
19 class BLTRParametersProc(ProcessingUnit):
21 METHODS = {}
20 '''
22 '''
21 Processing unit for BLTR parameters data (winds)
23 Processing unit for BLTR parameters data (winds)
22
24
23 Inputs:
25 Inputs:
24 self.dataOut.nmodes - Number of operation modes
26 self.dataOut.nmodes - Number of operation modes
25 self.dataOut.nchannels - Number of channels
27 self.dataOut.nchannels - Number of channels
26 self.dataOut.nranges - Number of ranges
28 self.dataOut.nranges - Number of ranges
27
29
28 self.dataOut.data_SNR - SNR array
30 self.dataOut.data_SNR - SNR array
29 self.dataOut.data_output - Zonal, Vertical and Meridional velocity array
31 self.dataOut.data_output - Zonal, Vertical and Meridional velocity array
30 self.dataOut.height - Height array (km)
32 self.dataOut.height - Height array (km)
31 self.dataOut.time - Time array (seconds)
33 self.dataOut.time - Time array (seconds)
32
34
33 self.dataOut.fileIndex -Index of the file currently read
35 self.dataOut.fileIndex -Index of the file currently read
34 self.dataOut.lat - Latitude coordinate of BLTR location
36 self.dataOut.lat - Latitude coordinate of BLTR location
35
37
36 self.dataOut.doy - Experiment doy (number of the day in the current year)
38 self.dataOut.doy - Experiment doy (number of the day in the current year)
37 self.dataOut.month - Experiment month
39 self.dataOut.month - Experiment month
38 self.dataOut.day - Experiment day
40 self.dataOut.day - Experiment day
39 self.dataOut.year - Experiment year
41 self.dataOut.year - Experiment year
40 '''
42 '''
41
43
42 def __init__(self, **kwargs):
44 def __init__(self):
43 '''
45 '''
44 Inputs: None
46 Inputs: None
45 '''
47 '''
46 ProcessingUnit.__init__(self, **kwargs)
48 ProcessingUnit.__init__(self)
49 self.setupReq = False
47 self.dataOut = Parameters()
50 self.dataOut = Parameters()
48 self.isConfig = False
51 self.isConfig = False
49
52
50 def setup(self, mode):
53 def setup(self, mode):
51 '''
54 '''
52 '''
55 '''
53 self.dataOut.mode = mode
56 self.dataOut.mode = mode
54
57
55 def run(self, mode, snr_threshold=None):
58 def run(self, mode, snr_threshold=None):
56 '''
59 '''
57 Inputs:
60 Inputs:
58 mode = High resolution (0) or Low resolution (1) data
61 mode = High resolution (0) or Low resolution (1) data
59 snr_threshold = snr filter value
62 snr_threshold = snr filter value
60 '''
63 '''
61
64
62 if not self.isConfig:
65 if not self.isConfig:
63 self.setup(mode)
66 self.setup(mode)
64 self.isConfig = True
67 self.isConfig = True
65
68
66 if self.dataIn.type == 'Parameters':
69 if self.dataIn.type == 'Parameters':
67 self.dataOut.copy(self.dataIn)
70 self.dataOut.copy(self.dataIn)
68
71
69 self.dataOut.data_param = self.dataOut.data[mode]
72 self.dataOut.data_param = self.dataOut.data[mode]
70 self.dataOut.heightList = self.dataOut.height[0]
73 self.dataOut.heightList = self.dataOut.height[0]
71 self.dataOut.data_SNR = self.dataOut.data_SNR[mode]
74 self.dataOut.data_SNR = self.dataOut.data_SNR[mode]
72
75
73 if snr_threshold is not None:
76 if snr_threshold is not None:
74 SNRavg = numpy.average(self.dataOut.data_SNR, axis=0)
77 SNRavg = numpy.average(self.dataOut.data_SNR, axis=0)
75 SNRavgdB = 10*numpy.log10(SNRavg)
78 SNRavgdB = 10*numpy.log10(SNRavg)
76 for i in range(3):
79 for i in range(3):
77 self.dataOut.data_param[i][SNRavgdB <= snr_threshold] = numpy.nan
80 self.dataOut.data_param[i][SNRavgdB <= snr_threshold] = numpy.nan
78
81
79 # TODO
82 # TODO
83 @MPDecorator
80 class OutliersFilter(Operation):
84 class OutliersFilter(Operation):
81
85
82 def __init__(self, **kwargs):
86 def __init__(self):
83 '''
87 '''
84 '''
88 '''
85 Operation.__init__(self, **kwargs)
89 Operation.__init__(self)
86
90
87 def run(self, svalue2, method, factor, filter, npoints=9):
91 def run(self, svalue2, method, factor, filter, npoints=9):
88 '''
92 '''
89 Inputs:
93 Inputs:
90 svalue - string to select array velocity
94 svalue - string to select array velocity
91 svalue2 - string to choose axis filtering
95 svalue2 - string to choose axis filtering
92 method - 0 for SMOOTH or 1 for MEDIAN
96 method - 0 for SMOOTH or 1 for MEDIAN
93 factor - number used to set threshold
97 factor - number used to set threshold
94 filter - 1 for data filtering using the standard deviation criteria else 0
98 filter - 1 for data filtering using the standard deviation criteria else 0
95 npoints - number of points for mask filter
99 npoints - number of points for mask filter
96 '''
100 '''
97
101
98 print(' Outliers Filter {} {} / threshold = {}'.format(svalue, svalue, factor))
102 print(' Outliers Filter {} {} / threshold = {}'.format(svalue, svalue, factor))
99
103
100
104
101 yaxis = self.dataOut.heightList
105 yaxis = self.dataOut.heightList
102 xaxis = numpy.array([[self.dataOut.utctime]])
106 xaxis = numpy.array([[self.dataOut.utctime]])
103
107
104 # Zonal
108 # Zonal
105 value_temp = self.dataOut.data_output[0]
109 value_temp = self.dataOut.data_output[0]
106
110
107 # Zonal
111 # Zonal
108 value_temp = self.dataOut.data_output[1]
112 value_temp = self.dataOut.data_output[1]
109
113
110 # Vertical
114 # Vertical
111 value_temp = numpy.transpose(self.dataOut.data_output[2])
115 value_temp = numpy.transpose(self.dataOut.data_output[2])
112
116
113 htemp = yaxis
117 htemp = yaxis
114 std = value_temp
118 std = value_temp
115 for h in range(len(htemp)):
119 for h in range(len(htemp)):
116 nvalues_valid = len(numpy.where(numpy.isfinite(value_temp[h]))[0])
120 nvalues_valid = len(numpy.where(numpy.isfinite(value_temp[h]))[0])
117 minvalid = npoints
121 minvalid = npoints
118
122
119 #only if valid values greater than the minimum required (10%)
123 #only if valid values greater than the minimum required (10%)
120 if nvalues_valid > minvalid:
124 if nvalues_valid > minvalid:
121
125
122 if method == 0:
126 if method == 0:
123 #SMOOTH
127 #SMOOTH
124 w = value_temp[h] - self.Smooth(input=value_temp[h], width=npoints, edge_truncate=1)
128 w = value_temp[h] - self.Smooth(input=value_temp[h], width=npoints, edge_truncate=1)
125
129
126
130
127 if method == 1:
131 if method == 1:
128 #MEDIAN
132 #MEDIAN
129 w = value_temp[h] - self.Median(input=value_temp[h], width = npoints)
133 w = value_temp[h] - self.Median(input=value_temp[h], width = npoints)
130
134
131 dw = numpy.std(w[numpy.where(numpy.isfinite(w))],ddof = 1)
135 dw = numpy.std(w[numpy.where(numpy.isfinite(w))],ddof = 1)
132
136
133 threshold = dw*factor
137 threshold = dw*factor
134 value_temp[numpy.where(w > threshold),h] = numpy.nan
138 value_temp[numpy.where(w > threshold),h] = numpy.nan
135 value_temp[numpy.where(w < -1*threshold),h] = numpy.nan
139 value_temp[numpy.where(w < -1*threshold),h] = numpy.nan
136
140
137
141
138 #At the end
142 #At the end
139 if svalue2 == 'inHeight':
143 if svalue2 == 'inHeight':
140 value_temp = numpy.transpose(value_temp)
144 value_temp = numpy.transpose(value_temp)
141 output_array[:,m] = value_temp
145 output_array[:,m] = value_temp
142
146
143 if svalue == 'zonal':
147 if svalue == 'zonal':
144 self.dataOut.data_output[0] = output_array
148 self.dataOut.data_output[0] = output_array
145
149
146 elif svalue == 'meridional':
150 elif svalue == 'meridional':
147 self.dataOut.data_output[1] = output_array
151 self.dataOut.data_output[1] = output_array
148
152
149 elif svalue == 'vertical':
153 elif svalue == 'vertical':
150 self.dataOut.data_output[2] = output_array
154 self.dataOut.data_output[2] = output_array
151
155
152 return self.dataOut.data_output
156 return self.dataOut.data_output
153
157
154
158
155 def Median(self,input,width):
159 def Median(self,input,width):
156 '''
160 '''
157 Inputs:
161 Inputs:
158 input - Velocity array
162 input - Velocity array
159 width - Number of points for mask filter
163 width - Number of points for mask filter
160
164
161 '''
165 '''
162
166
163 if numpy.mod(width,2) == 1:
167 if numpy.mod(width,2) == 1:
164 pc = int((width - 1) / 2)
168 pc = int((width - 1) / 2)
165 cont = 0
169 cont = 0
166 output = []
170 output = []
167
171
168 for i in range(len(input)):
172 for i in range(len(input)):
169 if i >= pc and i < len(input) - pc:
173 if i >= pc and i < len(input) - pc:
170 new2 = input[i-pc:i+pc+1]
174 new2 = input[i-pc:i+pc+1]
171 temp = numpy.where(numpy.isfinite(new2))
175 temp = numpy.where(numpy.isfinite(new2))
172 new = new2[temp]
176 new = new2[temp]
173 value = numpy.median(new)
177 value = numpy.median(new)
174 output.append(value)
178 output.append(value)
175
179
176 output = numpy.array(output)
180 output = numpy.array(output)
177 output = numpy.hstack((input[0:pc],output))
181 output = numpy.hstack((input[0:pc],output))
178 output = numpy.hstack((output,input[-pc:len(input)]))
182 output = numpy.hstack((output,input[-pc:len(input)]))
179
183
180 return output
184 return output
181
185
182 def Smooth(self,input,width,edge_truncate = None):
186 def Smooth(self,input,width,edge_truncate = None):
183 '''
187 '''
184 Inputs:
188 Inputs:
185 input - Velocity array
189 input - Velocity array
186 width - Number of points for mask filter
190 width - Number of points for mask filter
187 edge_truncate - 1 for truncate the convolution product else
191 edge_truncate - 1 for truncate the convolution product else
188
192
189 '''
193 '''
190
194
191 if numpy.mod(width,2) == 0:
195 if numpy.mod(width,2) == 0:
192 real_width = width + 1
196 real_width = width + 1
193 nzeros = width / 2
197 nzeros = width / 2
194 else:
198 else:
195 real_width = width
199 real_width = width
196 nzeros = (width - 1) / 2
200 nzeros = (width - 1) / 2
197
201
198 half_width = int(real_width)/2
202 half_width = int(real_width)/2
199 length = len(input)
203 length = len(input)
200
204
201 gate = numpy.ones(real_width,dtype='float')
205 gate = numpy.ones(real_width,dtype='float')
202 norm_of_gate = numpy.sum(gate)
206 norm_of_gate = numpy.sum(gate)
203
207
204 nan_process = 0
208 nan_process = 0
205 nan_id = numpy.where(numpy.isnan(input))
209 nan_id = numpy.where(numpy.isnan(input))
206 if len(nan_id[0]) > 0:
210 if len(nan_id[0]) > 0:
207 nan_process = 1
211 nan_process = 1
208 pb = numpy.zeros(len(input))
212 pb = numpy.zeros(len(input))
209 pb[nan_id] = 1.
213 pb[nan_id] = 1.
210 input[nan_id] = 0.
214 input[nan_id] = 0.
211
215
212 if edge_truncate == True:
216 if edge_truncate == True:
213 output = numpy.convolve(input/norm_of_gate,gate,mode='same')
217 output = numpy.convolve(input/norm_of_gate,gate,mode='same')
214 elif edge_truncate == False or edge_truncate == None:
218 elif edge_truncate == False or edge_truncate == None:
215 output = numpy.convolve(input/norm_of_gate,gate,mode='valid')
219 output = numpy.convolve(input/norm_of_gate,gate,mode='valid')
216 output = numpy.hstack((input[0:half_width],output))
220 output = numpy.hstack((input[0:half_width],output))
217 output = numpy.hstack((output,input[len(input)-half_width:len(input)]))
221 output = numpy.hstack((output,input[len(input)-half_width:len(input)]))
218
222
219 if nan_process:
223 if nan_process:
220 pb = numpy.convolve(pb/norm_of_gate,gate,mode='valid')
224 pb = numpy.convolve(pb/norm_of_gate,gate,mode='valid')
221 pb = numpy.hstack((numpy.zeros(half_width),pb))
225 pb = numpy.hstack((numpy.zeros(half_width),pb))
222 pb = numpy.hstack((pb,numpy.zeros(half_width)))
226 pb = numpy.hstack((pb,numpy.zeros(half_width)))
223 output[numpy.where(pb > 0.9999)] = numpy.nan
227 output[numpy.where(pb > 0.9999)] = numpy.nan
224 input[nan_id] = numpy.nan
228 input[nan_id] = numpy.nan
225 return output
229 return output
226
230
227 def Average(self,aver=0,nhaver=1):
231 def Average(self,aver=0,nhaver=1):
228 '''
232 '''
229 Inputs:
233 Inputs:
230 aver - Indicates the time period over which is averaged or consensus data
234 aver - Indicates the time period over which is averaged or consensus data
231 nhaver - Indicates the decimation factor in heights
235 nhaver - Indicates the decimation factor in heights
232
236
233 '''
237 '''
234 nhpoints = 48
238 nhpoints = 48
235
239
236 lat_piura = -5.17
240 lat_piura = -5.17
237 lat_huancayo = -12.04
241 lat_huancayo = -12.04
238 lat_porcuya = -5.8
242 lat_porcuya = -5.8
239
243
240 if '%2.2f'%self.dataOut.lat == '%2.2f'%lat_piura:
244 if '%2.2f'%self.dataOut.lat == '%2.2f'%lat_piura:
241 hcm = 3.
245 hcm = 3.
242 if self.dataOut.year == 2003 :
246 if self.dataOut.year == 2003 :
243 if self.dataOut.doy >= 25 and self.dataOut.doy < 64:
247 if self.dataOut.doy >= 25 and self.dataOut.doy < 64:
244 nhpoints = 12
248 nhpoints = 12
245
249
246 elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_huancayo:
250 elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_huancayo:
247 hcm = 3.
251 hcm = 3.
248 if self.dataOut.year == 2003 :
252 if self.dataOut.year == 2003 :
249 if self.dataOut.doy >= 25 and self.dataOut.doy < 64:
253 if self.dataOut.doy >= 25 and self.dataOut.doy < 64:
250 nhpoints = 12
254 nhpoints = 12
251
255
252
256
253 elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_porcuya:
257 elif '%2.2f'%self.dataOut.lat == '%2.2f'%lat_porcuya:
254 hcm = 5.#2
258 hcm = 5.#2
255
259
256 pdata = 0.2
260 pdata = 0.2
257 taver = [1,2,3,4,6,8,12,24]
261 taver = [1,2,3,4,6,8,12,24]
258 t0 = 0
262 t0 = 0
259 tf = 24
263 tf = 24
260 ntime =(tf-t0)/taver[aver]
264 ntime =(tf-t0)/taver[aver]
261 ti = numpy.arange(ntime)
265 ti = numpy.arange(ntime)
262 tf = numpy.arange(ntime) + taver[aver]
266 tf = numpy.arange(ntime) + taver[aver]
263
267
264
268
265 old_height = self.dataOut.heightList
269 old_height = self.dataOut.heightList
266
270
267 if nhaver > 1:
271 if nhaver > 1:
268 num_hei = len(self.dataOut.heightList)/nhaver/self.dataOut.nmodes
272 num_hei = len(self.dataOut.heightList)/nhaver/self.dataOut.nmodes
269 deltha = 0.05*nhaver
273 deltha = 0.05*nhaver
270 minhvalid = pdata*nhaver
274 minhvalid = pdata*nhaver
271 for im in range(self.dataOut.nmodes):
275 for im in range(self.dataOut.nmodes):
272 new_height = numpy.arange(num_hei)*deltha + self.dataOut.height[im,0] + deltha/2.
276 new_height = numpy.arange(num_hei)*deltha + self.dataOut.height[im,0] + deltha/2.
273
277
274
278
275 data_fHeigths_List = []
279 data_fHeigths_List = []
276 data_fZonal_List = []
280 data_fZonal_List = []
277 data_fMeridional_List = []
281 data_fMeridional_List = []
278 data_fVertical_List = []
282 data_fVertical_List = []
279 startDTList = []
283 startDTList = []
280
284
281
285
282 for i in range(ntime):
286 for i in range(ntime):
283 height = old_height
287 height = old_height
284
288
285 start = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(ti[i])) - datetime.timedelta(hours = 5)
289 start = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(ti[i])) - datetime.timedelta(hours = 5)
286 stop = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(tf[i])) - datetime.timedelta(hours = 5)
290 stop = datetime.datetime(self.dataOut.year,self.dataOut.month,self.dataOut.day) + datetime.timedelta(hours = int(tf[i])) - datetime.timedelta(hours = 5)
287
291
288
292
289 limit_sec1 = time.mktime(start.timetuple())
293 limit_sec1 = time.mktime(start.timetuple())
290 limit_sec2 = time.mktime(stop.timetuple())
294 limit_sec2 = time.mktime(stop.timetuple())
291
295
292 t1 = numpy.where(self.f_timesec >= limit_sec1)
296 t1 = numpy.where(self.f_timesec >= limit_sec1)
293 t2 = numpy.where(self.f_timesec < limit_sec2)
297 t2 = numpy.where(self.f_timesec < limit_sec2)
294 time_select = []
298 time_select = []
295 for val_sec in t1[0]:
299 for val_sec in t1[0]:
296 if val_sec in t2[0]:
300 if val_sec in t2[0]:
297 time_select.append(val_sec)
301 time_select.append(val_sec)
298
302
299
303
300 time_select = numpy.array(time_select,dtype = 'int')
304 time_select = numpy.array(time_select,dtype = 'int')
301 minvalid = numpy.ceil(pdata*nhpoints)
305 minvalid = numpy.ceil(pdata*nhpoints)
302
306
303 zon_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan
307 zon_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan
304 mer_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan
308 mer_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan
305 ver_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan
309 ver_aver = numpy.zeros([self.dataOut.nranges,self.dataOut.nmodes],dtype='f4') + numpy.nan
306
310
307 if nhaver > 1:
311 if nhaver > 1:
308 new_zon_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan
312 new_zon_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan
309 new_mer_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan
313 new_mer_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan
310 new_ver_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan
314 new_ver_aver = numpy.zeros([num_hei,self.dataOut.nmodes],dtype='f4') + numpy.nan
311
315
312 if len(time_select) > minvalid:
316 if len(time_select) > minvalid:
313 time_average = self.f_timesec[time_select]
317 time_average = self.f_timesec[time_select]
314
318
315 for im in range(self.dataOut.nmodes):
319 for im in range(self.dataOut.nmodes):
316
320
317 for ih in range(self.dataOut.nranges):
321 for ih in range(self.dataOut.nranges):
318 if numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im])) >= minvalid:
322 if numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im])) >= minvalid:
319 zon_aver[ih,im] = numpy.nansum(self.f_zon[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im]))
323 zon_aver[ih,im] = numpy.nansum(self.f_zon[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_zon[time_select,ih,im]))
320
324
321 if numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im])) >= minvalid:
325 if numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im])) >= minvalid:
322 mer_aver[ih,im] = numpy.nansum(self.f_mer[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im]))
326 mer_aver[ih,im] = numpy.nansum(self.f_mer[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_mer[time_select,ih,im]))
323
327
324 if numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im])) >= minvalid:
328 if numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im])) >= minvalid:
325 ver_aver[ih,im] = numpy.nansum(self.f_ver[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im]))
329 ver_aver[ih,im] = numpy.nansum(self.f_ver[time_select,ih,im]) / numpy.sum(numpy.isfinite(self.f_ver[time_select,ih,im]))
326
330
327 if nhaver > 1:
331 if nhaver > 1:
328 for ih in range(num_hei):
332 for ih in range(num_hei):
329 hvalid = numpy.arange(nhaver) + nhaver*ih
333 hvalid = numpy.arange(nhaver) + nhaver*ih
330
334
331 if numpy.sum(numpy.isfinite(zon_aver[hvalid,im])) >= minvalid:
335 if numpy.sum(numpy.isfinite(zon_aver[hvalid,im])) >= minvalid:
332 new_zon_aver[ih,im] = numpy.nansum(zon_aver[hvalid,im]) / numpy.sum(numpy.isfinite(zon_aver[hvalid,im]))
336 new_zon_aver[ih,im] = numpy.nansum(zon_aver[hvalid,im]) / numpy.sum(numpy.isfinite(zon_aver[hvalid,im]))
333
337
334 if numpy.sum(numpy.isfinite(mer_aver[hvalid,im])) >= minvalid:
338 if numpy.sum(numpy.isfinite(mer_aver[hvalid,im])) >= minvalid:
335 new_mer_aver[ih,im] = numpy.nansum(mer_aver[hvalid,im]) / numpy.sum(numpy.isfinite(mer_aver[hvalid,im]))
339 new_mer_aver[ih,im] = numpy.nansum(mer_aver[hvalid,im]) / numpy.sum(numpy.isfinite(mer_aver[hvalid,im]))
336
340
337 if numpy.sum(numpy.isfinite(ver_aver[hvalid,im])) >= minvalid:
341 if numpy.sum(numpy.isfinite(ver_aver[hvalid,im])) >= minvalid:
338 new_ver_aver[ih,im] = numpy.nansum(ver_aver[hvalid,im]) / numpy.sum(numpy.isfinite(ver_aver[hvalid,im]))
342 new_ver_aver[ih,im] = numpy.nansum(ver_aver[hvalid,im]) / numpy.sum(numpy.isfinite(ver_aver[hvalid,im]))
339 if nhaver > 1:
343 if nhaver > 1:
340 zon_aver = new_zon_aver
344 zon_aver = new_zon_aver
341 mer_aver = new_mer_aver
345 mer_aver = new_mer_aver
342 ver_aver = new_ver_aver
346 ver_aver = new_ver_aver
343 height = new_height
347 height = new_height
344
348
345
349
346 tstart = time_average[0]
350 tstart = time_average[0]
347 tend = time_average[-1]
351 tend = time_average[-1]
348 startTime = time.gmtime(tstart)
352 startTime = time.gmtime(tstart)
349
353
350 year = startTime.tm_year
354 year = startTime.tm_year
351 month = startTime.tm_mon
355 month = startTime.tm_mon
352 day = startTime.tm_mday
356 day = startTime.tm_mday
353 hour = startTime.tm_hour
357 hour = startTime.tm_hour
354 minute = startTime.tm_min
358 minute = startTime.tm_min
355 second = startTime.tm_sec
359 second = startTime.tm_sec
356
360
357 startDTList.append(datetime.datetime(year,month,day,hour,minute,second))
361 startDTList.append(datetime.datetime(year,month,day,hour,minute,second))
358
362
359
363
360 o_height = numpy.array([])
364 o_height = numpy.array([])
361 o_zon_aver = numpy.array([])
365 o_zon_aver = numpy.array([])
362 o_mer_aver = numpy.array([])
366 o_mer_aver = numpy.array([])
363 o_ver_aver = numpy.array([])
367 o_ver_aver = numpy.array([])
364 if self.dataOut.nmodes > 1:
368 if self.dataOut.nmodes > 1:
365 for im in range(self.dataOut.nmodes):
369 for im in range(self.dataOut.nmodes):
366
370
367 if im == 0:
371 if im == 0:
368 h_select = numpy.where(numpy.bitwise_and(height[0,:] >=0,height[0,:] <= hcm,numpy.isfinite(height[0,:])))
372 h_select = numpy.where(numpy.bitwise_and(height[0,:] >=0,height[0,:] <= hcm,numpy.isfinite(height[0,:])))
369 else:
373 else:
370 h_select = numpy.where(numpy.bitwise_and(height[1,:] > hcm,height[1,:] < 20,numpy.isfinite(height[1,:])))
374 h_select = numpy.where(numpy.bitwise_and(height[1,:] > hcm,height[1,:] < 20,numpy.isfinite(height[1,:])))
371
375
372
376
373 ht = h_select[0]
377 ht = h_select[0]
374
378
375 o_height = numpy.hstack((o_height,height[im,ht]))
379 o_height = numpy.hstack((o_height,height[im,ht]))
376 o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im]))
380 o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im]))
377 o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im]))
381 o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im]))
378 o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im]))
382 o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im]))
379
383
380 data_fHeigths_List.append(o_height)
384 data_fHeigths_List.append(o_height)
381 data_fZonal_List.append(o_zon_aver)
385 data_fZonal_List.append(o_zon_aver)
382 data_fMeridional_List.append(o_mer_aver)
386 data_fMeridional_List.append(o_mer_aver)
383 data_fVertical_List.append(o_ver_aver)
387 data_fVertical_List.append(o_ver_aver)
384
388
385
389
386 else:
390 else:
387 h_select = numpy.where(numpy.bitwise_and(height[0,:] <= hcm,numpy.isfinite(height[0,:])))
391 h_select = numpy.where(numpy.bitwise_and(height[0,:] <= hcm,numpy.isfinite(height[0,:])))
388 ht = h_select[0]
392 ht = h_select[0]
389 o_height = numpy.hstack((o_height,height[im,ht]))
393 o_height = numpy.hstack((o_height,height[im,ht]))
390 o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im]))
394 o_zon_aver = numpy.hstack((o_zon_aver,zon_aver[ht,im]))
391 o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im]))
395 o_mer_aver = numpy.hstack((o_mer_aver,mer_aver[ht,im]))
392 o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im]))
396 o_ver_aver = numpy.hstack((o_ver_aver,ver_aver[ht,im]))
393
397
394 data_fHeigths_List.append(o_height)
398 data_fHeigths_List.append(o_height)
395 data_fZonal_List.append(o_zon_aver)
399 data_fZonal_List.append(o_zon_aver)
396 data_fMeridional_List.append(o_mer_aver)
400 data_fMeridional_List.append(o_mer_aver)
397 data_fVertical_List.append(o_ver_aver)
401 data_fVertical_List.append(o_ver_aver)
398
402
399
403
400 return startDTList, data_fHeigths_List, data_fZonal_List, data_fMeridional_List, data_fVertical_List
404 return startDTList, data_fHeigths_List, data_fZonal_List, data_fMeridional_List, data_fVertical_List
401
405
402
406
General Comments 0
You need to be logged in to leave comments. Login now