@@ -82,6 +82,7 DATA_STRUCTURE = numpy.dtype([ | |||||
82 | ('sea_algorithm', '<u4') |
|
82 | ('sea_algorithm', '<u4') | |
83 | ]) |
|
83 | ]) | |
84 |
|
84 | |||
|
85 | ||||
85 | class BLTRParamReader(JRODataReader, ProcessingUnit): |
|
86 | class BLTRParamReader(JRODataReader, ProcessingUnit): | |
86 | ''' |
|
87 | ''' | |
87 | Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files |
|
88 | Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files | |
@@ -91,14 +92,14 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
91 |
|
92 | |||
92 | def __init__(self, **kwargs): |
|
93 | def __init__(self, **kwargs): | |
93 |
|
94 | |||
94 |
ProcessingUnit.__init__(self |
|
95 | ProcessingUnit.__init__(self, **kwargs) | |
95 |
|
96 | |||
96 |
self.dataOut = Parameters() |
|
97 | self.dataOut = Parameters() | |
97 | self.counter_records = 0 |
|
98 | self.counter_records = 0 | |
98 | self.flagNoMoreFiles = 0 |
|
99 | self.flagNoMoreFiles = 0 | |
99 |
self.isConfig = False |
|
100 | self.isConfig = False | |
100 | self.filename = None |
|
101 | self.filename = None | |
101 |
|
102 | |||
102 | def setup(self, |
|
103 | def setup(self, | |
103 | path=None, |
|
104 | path=None, | |
104 | startDate=None, |
|
105 | startDate=None, | |
@@ -107,18 +108,17 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
107 | startTime=datetime.time(0, 0, 0), |
|
108 | startTime=datetime.time(0, 0, 0), | |
108 | endTime=datetime.time(23, 59, 59), |
|
109 | endTime=datetime.time(23, 59, 59), | |
109 | timezone=0, |
|
110 | timezone=0, | |
110 | status_value=0, |
|
111 | status_value=0, **kwargs): | |
111 | **kwargs): |
|
112 | ||
112 |
|
||||
113 | self.path = path |
|
113 | self.path = path | |
114 | self.startTime = startTime |
|
114 | self.startTime = startTime | |
115 |
self.endTime = endTime |
|
115 | self.endTime = endTime | |
116 | self.status_value = status_value |
|
116 | self.status_value = status_value | |
117 |
|
117 | |||
118 | if self.path is None: |
|
118 | if self.path is None: | |
119 | raise ValueError, "The path is not valid" |
|
119 | raise ValueError, "The path is not valid" | |
120 |
|
120 | |||
121 |
if ext is None: |
|
121 | if ext is None: | |
122 | ext = self.ext |
|
122 | ext = self.ext | |
123 |
|
123 | |||
124 | self.search_files(self.path, startDate, endDate, ext) |
|
124 | self.search_files(self.path, startDate, endDate, ext) | |
@@ -126,50 +126,51 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
126 | self.fileIndex = 0 |
|
126 | self.fileIndex = 0 | |
127 |
|
127 | |||
128 | if not self.fileList: |
|
128 | if not self.fileList: | |
129 |
raise |
|
129 | raise Warning, "There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % ( | |
|
130 | path) | |||
130 |
|
131 | |||
131 | self.setNextFile() |
|
132 | self.setNextFile() | |
132 |
|
133 | |||
133 | def search_files(self, path, startDate, endDate, ext): |
|
134 | def search_files(self, path, startDate, endDate, ext): | |
134 | ''' |
|
135 | ''' | |
135 | Searching for BLTR rawdata file in path |
|
136 | Searching for BLTR rawdata file in path | |
136 | Creating a list of file to proces included in [startDate,endDate] |
|
137 | Creating a list of file to proces included in [startDate,endDate] | |
137 |
|
138 | |||
138 | Input: |
|
139 | Input: | |
139 | path - Path to find BLTR rawdata files |
|
140 | path - Path to find BLTR rawdata files | |
140 | startDate - Select file from this date |
|
141 | startDate - Select file from this date | |
141 | enDate - Select file until this date |
|
142 | enDate - Select file until this date | |
142 | ext - Extension of the file to read |
|
143 | ext - Extension of the file to read | |
143 |
|
||||
144 | ''' |
|
|||
145 |
|
|
144 | ||
146 | print 'Searching file in %s ' % (path) |
|
145 | ''' | |
147 | foldercounter = 0 |
|
146 | ||
|
147 | print 'Searching file in %s ' % (path) | |||
|
148 | foldercounter = 0 | |||
148 | fileList0 = glob.glob1(path, "*%s" % ext) |
|
149 | fileList0 = glob.glob1(path, "*%s" % ext) | |
149 | fileList0.sort() |
|
150 | fileList0.sort() | |
150 |
|
151 | |||
151 | self.fileList = [] |
|
152 | self.fileList = [] | |
152 | self.dateFileList = [] |
|
153 | self.dateFileList = [] | |
153 |
|
154 | |||
154 |
for thisFile in fileList0: |
|
155 | for thisFile in fileList0: | |
155 | year = thisFile[-14:-10] |
|
156 | year = thisFile[-14:-10] | |
156 | if not isNumber(year): |
|
157 | if not isNumber(year): | |
157 | continue |
|
158 | continue | |
158 |
|
159 | |||
159 | month = thisFile[-10:-8] |
|
160 | month = thisFile[-10:-8] | |
160 | if not isNumber(month): |
|
161 | if not isNumber(month): | |
161 | continue |
|
162 | continue | |
162 |
|
163 | |||
163 | day = thisFile[-8:-6] |
|
164 | day = thisFile[-8:-6] | |
164 | if not isNumber(day): |
|
165 | if not isNumber(day): | |
165 |
continue |
|
166 | continue | |
166 |
|
167 | |||
167 | year, month, day = int(year), int(month), int(day) |
|
168 | year, month, day = int(year), int(month), int(day) | |
168 | dateFile = datetime.date(year, month, day) |
|
169 | dateFile = datetime.date(year, month, day) | |
169 |
|
170 | |||
170 | if (startDate > dateFile) or (endDate < dateFile): |
|
171 | if (startDate > dateFile) or (endDate < dateFile): | |
171 | continue |
|
172 | continue | |
172 |
|
173 | |||
173 | self.fileList.append(thisFile) |
|
174 | self.fileList.append(thisFile) | |
174 | self.dateFileList.append(dateFile) |
|
175 | self.dateFileList.append(dateFile) | |
175 |
|
176 | |||
@@ -181,22 +182,23 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
181 |
|
182 | |||
182 | if file_id == len(self.fileList): |
|
183 | if file_id == len(self.fileList): | |
183 | print '\nNo more files in the folder' |
|
184 | print '\nNo more files in the folder' | |
184 |
print 'Total number of file(s) read : {}'.format(self.fileIndex + 1) |
|
185 | print 'Total number of file(s) read : {}'.format(self.fileIndex + 1) | |
185 | self.flagNoMoreFiles = 1 |
|
186 | self.flagNoMoreFiles = 1 | |
186 | return 0 |
|
187 | return 0 | |
187 |
|
188 | |||
188 | print '\n[Setting file] (%s) ...' % self.fileList[file_id] |
|
189 | print '\n[Setting file] (%s) ...' % self.fileList[file_id] | |
189 | filename = os.path.join(self.path, self.fileList[file_id]) |
|
190 | filename = os.path.join(self.path, self.fileList[file_id]) | |
190 |
|
191 | |||
191 | dirname, name = os.path.split(filename) |
|
192 | dirname, name = os.path.split(filename) | |
192 |
|
|
193 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya | |
|
194 | self.siteFile = name.split('.')[0] | |||
193 | if self.filename is not None: |
|
195 | if self.filename is not None: | |
194 | self.fp.close() |
|
196 | self.fp.close() | |
195 | self.filename = filename |
|
197 | self.filename = filename | |
196 | self.fp = open(self.filename, 'rb') |
|
198 | self.fp = open(self.filename, 'rb') | |
197 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) |
|
199 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) | |
198 | self.nrecords = self.header_file['nrec'][0] |
|
200 | self.nrecords = self.header_file['nrec'][0] | |
199 |
self.sizeOfFile = os.path.getsize(self.filename) |
|
201 | self.sizeOfFile = os.path.getsize(self.filename) | |
200 | self.counter_records = 0 |
|
202 | self.counter_records = 0 | |
201 | self.flagIsNewFile = 0 |
|
203 | self.flagIsNewFile = 0 | |
202 | self.fileIndex += 1 |
|
204 | self.fileIndex += 1 | |
@@ -205,23 +207,23 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
205 |
|
207 | |||
206 | def readNextBlock(self): |
|
208 | def readNextBlock(self): | |
207 |
|
209 | |||
208 |
while True: |
|
210 | while True: | |
209 | if self.counter_records == self.nrecords: |
|
211 | if self.counter_records == self.nrecords: | |
210 | self.flagIsNewFile = 1 |
|
212 | self.flagIsNewFile = 1 | |
211 | if not self.setNextFile(): |
|
213 | if not self.setNextFile(): | |
212 | return 0 |
|
214 | return 0 | |
213 |
|
215 | |||
214 | self.readBlock() |
|
216 | self.readBlock() | |
215 |
|
217 | |||
216 | if (self.datatime.time() < self.startTime) or (self.datatime.time() > self.endTime): |
|
218 | if (self.datatime.time() < self.startTime) or (self.datatime.time() > self.endTime): | |
217 | print "[Reading] Record No. %d/%d -> %s [Skipping]" %( |
|
219 | print "[Reading] Record No. %d/%d -> %s [Skipping]" % ( | |
218 | self.counter_records, |
|
220 | self.counter_records, | |
219 | self.nrecords, |
|
221 | self.nrecords, | |
220 | self.datatime.ctime()) |
|
222 | self.datatime.ctime()) | |
221 | continue |
|
223 | continue | |
222 | break |
|
224 | break | |
223 |
|
225 | |||
224 | print "[Reading] Record No. %d/%d -> %s" %( |
|
226 | print "[Reading] Record No. %d/%d -> %s" % ( | |
225 | self.counter_records, |
|
227 | self.counter_records, | |
226 | self.nrecords, |
|
228 | self.nrecords, | |
227 | self.datatime.ctime()) |
|
229 | self.datatime.ctime()) | |
@@ -232,7 +234,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
232 |
|
234 | |||
233 | pointer = self.fp.tell() |
|
235 | pointer = self.fp.tell() | |
234 | header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) |
|
236 | header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) | |
235 | self.nchannels = header_rec['nchan'][0]/2 |
|
237 | self.nchannels = header_rec['nchan'][0] / 2 | |
236 | self.kchan = header_rec['nrxs'][0] |
|
238 | self.kchan = header_rec['nrxs'][0] | |
237 | self.nmodes = header_rec['nmodes'][0] |
|
239 | self.nmodes = header_rec['nmodes'][0] | |
238 | self.nranges = header_rec['nranges'][0] |
|
240 | self.nranges = header_rec['nranges'][0] | |
@@ -242,7 +244,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
242 | self.buffer = numpy.empty((self.nmodes, 3, self.nranges)) |
|
244 | self.buffer = numpy.empty((self.nmodes, 3, self.nranges)) | |
243 |
|
245 | |||
244 | for mode in range(self.nmodes): |
|
246 | for mode in range(self.nmodes): | |
245 |
self.readHeader() |
|
247 | self.readHeader() | |
246 | data = self.readData() |
|
248 | data = self.readData() | |
247 | self.height[mode] = (data[0] - self.correction) / 1000. |
|
249 | self.height[mode] = (data[0] - self.correction) / 1000. | |
248 | self.buffer[mode] = data[1] |
|
250 | self.buffer[mode] = data[1] | |
@@ -256,7 +258,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
256 | ''' |
|
258 | ''' | |
257 | RecordHeader of BLTR rawdata file |
|
259 | RecordHeader of BLTR rawdata file | |
258 | ''' |
|
260 | ''' | |
259 |
|
261 | |||
260 | header_structure = numpy.dtype( |
|
262 | header_structure = numpy.dtype( | |
261 | REC_HEADER_STRUCTURE.descr + [ |
|
263 | REC_HEADER_STRUCTURE.descr + [ | |
262 | ('antenna_coord', 'f4', (2, self.nchannels)), |
|
264 | ('antenna_coord', 'f4', (2, self.nchannels)), | |
@@ -270,9 +272,9 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
270 | self.lon = self.header_rec['lon'][0] |
|
272 | self.lon = self.header_rec['lon'][0] | |
271 | self.delta = self.header_rec['delta_r'][0] |
|
273 | self.delta = self.header_rec['delta_r'][0] | |
272 | self.correction = self.header_rec['dmode_rngcorr'][0] |
|
274 | self.correction = self.header_rec['dmode_rngcorr'][0] | |
273 |
self.imode = self.header_rec['dmode_index'][0] |
|
275 | self.imode = self.header_rec['dmode_index'][0] | |
274 | self.antenna = self.header_rec['antenna_coord'] |
|
276 | self.antenna = self.header_rec['antenna_coord'] | |
275 |
self.rx_gains = self.header_rec['rx_gains'] |
|
277 | self.rx_gains = self.header_rec['rx_gains'] | |
276 | self.time = self.header_rec['time'][0] |
|
278 | self.time = self.header_rec['time'][0] | |
277 | tseconds = self.header_rec['time'][0] |
|
279 | tseconds = self.header_rec['time'][0] | |
278 | local_t1 = time.localtime(tseconds) |
|
280 | local_t1 = time.localtime(tseconds) | |
@@ -281,7 +283,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
281 | self.day = local_t1.tm_mday |
|
283 | self.day = local_t1.tm_mday | |
282 | self.t = datetime.datetime(self.year, self.month, self.day) |
|
284 | self.t = datetime.datetime(self.year, self.month, self.day) | |
283 | self.datatime = datetime.datetime.utcfromtimestamp(self.time) |
|
285 | self.datatime = datetime.datetime.utcfromtimestamp(self.time) | |
284 |
|
286 | |||
285 | def readData(self): |
|
287 | def readData(self): | |
286 | ''' |
|
288 | ''' | |
287 | Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value. |
|
289 | Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value. | |
@@ -304,22 +306,23 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
304 | data = numpy.fromfile(self.fp, data_structure, self.nranges) |
|
306 | data = numpy.fromfile(self.fp, data_structure, self.nranges) | |
305 |
|
307 | |||
306 | height = data['range'] |
|
308 | height = data['range'] | |
307 | winds = numpy.array((data['zonal'], data['meridional'], data['vertical'])) |
|
309 | winds = numpy.array( | |
|
310 | (data['zonal'], data['meridional'], data['vertical'])) | |||
308 | snr = data['rx_snr'].T |
|
311 | snr = data['rx_snr'].T | |
309 |
|
312 | |||
310 |
winds[numpy.where(winds == -9999.)] = numpy.nan |
|
313 | winds[numpy.where(winds == -9999.)] = numpy.nan | |
311 | winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
314 | winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan | |
312 | snr[numpy.where(snr == -9999.)] = numpy.nan |
|
315 | snr[numpy.where(snr == -9999.)] = numpy.nan | |
313 | snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
316 | snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan | |
314 |
snr = numpy.power(10, snr / 10) |
|
317 | snr = numpy.power(10, snr / 10) | |
315 |
|
318 | |||
316 | return height, winds, snr |
|
319 | return height, winds, snr | |
317 |
|
320 | |||
318 | def set_output(self): |
|
321 | def set_output(self): | |
319 | ''' |
|
322 | ''' | |
320 | Storing data from databuffer to dataOut object |
|
323 | Storing data from databuffer to dataOut object | |
321 | ''' |
|
324 | ''' | |
322 |
|
325 | |||
323 | self.dataOut.data_SNR = self.snr |
|
326 | self.dataOut.data_SNR = self.snr | |
324 | self.dataOut.height = self.height |
|
327 | self.dataOut.height = self.height | |
325 | self.dataOut.data_output = self.buffer |
|
328 | self.dataOut.data_output = self.buffer | |
@@ -329,7 +332,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
329 | self.dataOut.paramInterval = 157 |
|
332 | self.dataOut.paramInterval = 157 | |
330 | self.dataOut.timezone = self.timezone |
|
333 | self.dataOut.timezone = self.timezone | |
331 | self.dataOut.site = self.siteFile |
|
334 | self.dataOut.site = self.siteFile | |
332 | self.dataOut.nrecords = self.nrecords/self.nmodes |
|
335 | self.dataOut.nrecords = self.nrecords / self.nmodes | |
333 | self.dataOut.sizeOfFile = self.sizeOfFile |
|
336 | self.dataOut.sizeOfFile = self.sizeOfFile | |
334 | self.dataOut.lat = self.lat |
|
337 | self.dataOut.lat = self.lat | |
335 | self.dataOut.lon = self.lon |
|
338 | self.dataOut.lon = self.lon | |
@@ -353,7 +356,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||||
353 | print 'No file left to process' |
|
356 | print 'No file left to process' | |
354 | return 0 |
|
357 | return 0 | |
355 |
|
358 | |||
356 |
if not |
|
359 | if not self.readNextBlock(): | |
357 | self.dataOut.flagNoData = True |
|
360 | self.dataOut.flagNoData = True | |
358 | return 0 |
|
361 | return 0 | |
359 |
|
362 |
General Comments 0
You need to be logged in to leave comments.
Login now