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