@@ -1,409 +1,406 | |||||
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, MPDecorator |
|
16 | from schainpy.model.proc.jroproc_base import ProcessingUnit, 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 | @MPDecorator |
|
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 |
|
89 | Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR | |
|
90 | from *.sswma files | |||
90 | ''' |
|
91 | ''' | |
91 |
|
92 | |||
92 | ext = '.sswma' |
|
93 | ext = '.sswma' | |
93 |
|
94 | |||
94 | def __init__(self): |
|
95 | def __init__(self): | |
95 |
|
96 | |||
96 | ProcessingUnit.__init__(self) |
|
97 | ProcessingUnit.__init__(self) | |
97 |
|
98 | |||
98 | self.dataOut = Parameters() |
|
99 | self.dataOut = Parameters() | |
99 | self.counter_records = 0 |
|
100 | self.counter_records = 0 | |
100 | self.flagNoMoreFiles = 0 |
|
101 | self.flagNoMoreFiles = 0 | |
101 | self.isConfig = False |
|
102 | self.isConfig = False | |
102 | self.filename = None |
|
103 | self.filename = None | |
103 |
|
104 | |||
104 | def setup(self, |
|
105 | def setup(self, | |
105 | path=None, |
|
106 | path=None, | |
106 | startDate=None, |
|
107 | startDate=None, | |
107 | endDate=None, |
|
108 | endDate=None, | |
108 | ext=None, |
|
109 | ext=None, | |
109 | startTime=datetime.time(0, 0, 0), |
|
110 | startTime=datetime.time(0, 0, 0), | |
110 | endTime=datetime.time(23, 59, 59), |
|
111 | endTime=datetime.time(23, 59, 59), | |
111 | timezone=0, |
|
112 | timezone=0, | |
112 | status_value=0, |
|
113 | status_value=0, | |
113 | **kwargs): |
|
114 | **kwargs): | |
114 | self.path = path |
|
115 | self.path = path | |
115 | self.startDate = startDate |
|
116 | self.startDate = startDate | |
116 | self.endDate = endDate |
|
117 | self.endDate = endDate | |
117 | self.startTime = startTime |
|
118 | self.startTime = startTime | |
118 | self.endTime = endTime |
|
119 | self.endTime = endTime | |
119 | self.status_value = status_value |
|
120 | self.status_value = status_value | |
120 | self.datatime = datetime.datetime(1900,1,1) |
|
121 | self.datatime = datetime.datetime(1900,1,1) | |
121 | self.delay = kwargs.get('delay', 10) |
|
122 | self.delay = kwargs.get('delay', 10) | |
122 | self.online = kwargs.get('online', False) |
|
123 | self.online = kwargs.get('online', False) | |
123 | self.nTries = kwargs.get('nTries', 3) |
|
124 | self.nTries = kwargs.get('nTries', 3) | |
124 |
|
125 | |||
125 | if self.path is None: |
|
126 | if self.path is None: | |
126 | raise ValueError("The path is not valid") |
|
127 | raise ValueError("The path is not valid") | |
127 |
|
128 | |||
128 | if ext is None: |
|
129 | if ext is None: | |
129 | ext = self.ext |
|
130 | ext = self.ext | |
130 |
|
131 | |||
131 | self.fileList = self.search_files(self.path, startDate, endDate, ext) |
|
132 | self.fileList = self.search_files(self.path, startDate, endDate, ext) | |
132 | self.timezone = timezone |
|
133 | self.timezone = timezone | |
133 | self.fileIndex = 0 |
|
134 | self.fileIndex = 0 | |
134 |
|
135 | |||
135 | if not self.fileList: |
|
136 | if not self.fileList: | |
136 | raise Warning("There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % ( |
|
137 | raise Warning("There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % ( | |
137 | path)) |
|
138 | path)) | |
138 |
|
139 | |||
139 | self.setNextFile() |
|
140 | self.setNextFile() | |
140 |
|
141 | |||
141 | def search_last_file(self): |
|
142 | def search_last_file(self): | |
142 | ''' |
|
143 | ''' | |
143 | Get last file and add it to the list |
|
144 | Get last file and add it to the list | |
144 | ''' |
|
145 | ''' | |
145 |
|
146 | |||
146 | for n in range(self.nTries): |
|
147 | for n in range(self.nTries): | |
147 | if n > 0: |
|
|||
148 |
|
|
148 | log.warning( | |
149 |
|
|
149 | "Waiting %0.2f seconds for the next file, try %03d ..." % (self.delay, n+1), | |
150 |
|
|
150 | self.name | |
151 |
|
|
151 | ) | |
152 |
|
|
152 | time.sleep(self.delay) | |
153 | file_list = os.listdir(self.path) |
|
153 | file_list = os.listdir(self.path) | |
154 | file_list.sort() |
|
154 | file_list.sort() | |
155 | if file_list: |
|
155 | if file_list: | |
156 | if self.filename: |
|
156 | if self.filename: | |
157 | if file_list[-1] not in self.filename: |
|
157 | if file_list[-1] not in self.filename: | |
158 | return file_list[-1] |
|
158 | return file_list[-1] | |
159 | else: |
|
159 | else: | |
160 | continue |
|
160 | continue | |
161 | return file_list[-1] |
|
161 | return file_list[-1] | |
162 | return 0 |
|
162 | return 0 | |
163 |
|
163 | |||
164 | def search_files(self, path, startDate, endDate, ext): |
|
164 | def search_files(self, path, startDate, endDate, ext): | |
165 | ''' |
|
165 | ''' | |
166 | Searching for BLTR rawdata file in path |
|
166 | Searching for BLTR rawdata file in path | |
167 | Creating a list of file to proces included in [startDate,endDate] |
|
167 | Creating a list of file to proces included in [startDate,endDate] | |
168 |
|
168 | |||
169 | Input: |
|
169 | Input: | |
170 | path - Path to find BLTR rawdata files |
|
170 | path - Path to find BLTR rawdata files | |
171 | startDate - Select file from this date |
|
171 | startDate - Select file from this date | |
172 | enDate - Select file until this date |
|
172 | enDate - Select file until this date | |
173 | ext - Extension of the file to read |
|
173 | ext - Extension of the file to read | |
174 | ''' |
|
174 | ''' | |
175 |
|
175 | |||
176 | log.success('Searching files in {} '.format(path), 'BLTRParamReader') |
|
176 | log.success('Searching files in {} '.format(path), 'BLTRParamReader') | |
177 | foldercounter = 0 |
|
177 | foldercounter = 0 | |
178 | fileList0 = glob.glob1(path, "*%s" % ext) |
|
178 | fileList0 = glob.glob1(path, "*%s" % ext) | |
179 | fileList0.sort() |
|
179 | fileList0.sort() | |
180 |
|
180 | |||
181 | #self.fileList = [] |
|
|||
182 | #self.dateFileList = [] |
|
|||
183 |
|
||||
184 | for thisFile in fileList0: |
|
181 | for thisFile in fileList0: | |
185 | year = thisFile[-14:-10] |
|
182 | year = thisFile[-14:-10] | |
186 | if not isNumber(year): |
|
183 | if not isNumber(year): | |
187 | continue |
|
184 | continue | |
188 |
|
185 | |||
189 | month = thisFile[-10:-8] |
|
186 | month = thisFile[-10:-8] | |
190 | if not isNumber(month): |
|
187 | if not isNumber(month): | |
191 | continue |
|
188 | continue | |
192 |
|
189 | |||
193 | day = thisFile[-8:-6] |
|
190 | day = thisFile[-8:-6] | |
194 | if not isNumber(day): |
|
191 | if not isNumber(day): | |
195 | continue |
|
192 | continue | |
196 |
|
193 | |||
197 | year, month, day = int(year), int(month), int(day) |
|
194 | year, month, day = int(year), int(month), int(day) | |
198 | dateFile = datetime.date(year, month, day) |
|
195 | dateFile = datetime.date(year, month, day) | |
199 |
|
196 | |||
200 | if (startDate > dateFile) or (endDate < dateFile): |
|
197 | if (startDate > dateFile) or (endDate < dateFile): | |
201 | continue |
|
198 | continue | |
202 |
|
199 | |||
203 | yield thisFile |
|
200 | yield thisFile | |
204 | # self.dateFileList.append(dateFile) |
|
|||
205 |
|
201 | |||
206 | return |
|
202 | return | |
207 |
|
203 | |||
208 | def setNextFile(self): |
|
204 | def setNextFile(self): | |
209 |
|
205 | |||
210 | if self.online: |
|
206 | if self.online: | |
211 | filename = self.search_last_file() |
|
207 | filename = self.search_last_file() | |
212 | if not filename: |
|
208 | if not filename: | |
213 | self.flagNoMoreFiles = 1 |
|
209 | self.flagNoMoreFiles = 1 | |
214 | return 0 |
|
210 | return 0 | |
215 | else: |
|
211 | else: | |
216 | try: |
|
212 | try: | |
217 | filename = next(self.fileList) |
|
213 | filename = next(self.fileList) | |
218 | except StopIteration: |
|
214 | except StopIteration: | |
219 | print('Noooo files') |
|
|||
220 | self.flagNoMoreFiles = 1 |
|
215 | self.flagNoMoreFiles = 1 | |
221 | return 0 |
|
216 | return 0 | |
222 |
|
217 | |||
223 | log.success('Opening {}'.format(filename), 'BLTRParamReader') |
|
218 | log.success('Opening {}'.format(filename), 'BLTRParamReader') | |
224 |
|
219 | |||
225 | dirname, name = os.path.split(filename) |
|
220 | dirname, name = os.path.split(filename) | |
226 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya |
|
221 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya | |
227 | self.siteFile = filename.split('.')[0] |
|
222 | self.siteFile = filename.split('.')[0] | |
228 | if self.filename is not None: |
|
223 | if self.filename is not None: | |
229 | self.fp.close() |
|
224 | self.fp.close() | |
230 | self.filename = os.path.join(self.path, filename) |
|
225 | self.filename = os.path.join(self.path, filename) | |
231 | self.fp = open(self.filename, 'rb') |
|
226 | self.fp = open(self.filename, 'rb') | |
232 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) |
|
227 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) | |
233 | self.nrecords = self.header_file['nrec'][0] |
|
228 | self.nrecords = self.header_file['nrec'][0] | |
234 | self.sizeOfFile = os.path.getsize(self.filename) |
|
229 | self.sizeOfFile = os.path.getsize(self.filename) | |
235 | self.counter_records = 0 |
|
230 | self.counter_records = 0 | |
236 | self.flagIsNewFile = 0 |
|
231 | self.flagIsNewFile = 0 | |
237 | self.fileIndex += 1 |
|
232 | self.fileIndex += 1 | |
238 |
|
233 | |||
239 | return 1 |
|
234 | return 1 | |
240 |
|
235 | |||
241 | def readNextBlock(self): |
|
236 | def readNextBlock(self): | |
242 |
|
237 | |||
243 | while True: |
|
238 | while True: | |
244 | if self.counter_records == self.nrecords: |
|
239 | if not self.online and self.counter_records == self.nrecords: | |
245 | self.flagIsNewFile = 1 |
|
240 | self.flagIsNewFile = 1 | |
246 | if not self.setNextFile(): |
|
241 | if not self.setNextFile(): | |
247 | return 0 |
|
242 | return 0 | |
248 |
|
243 | |||
249 | try: |
|
244 | try: | |
250 | pointer = self.fp.tell() |
|
245 | pointer = self.fp.tell() | |
251 | self.readBlock() |
|
246 | self.readBlock() | |
252 | except: |
|
247 | except: | |
253 | if self.waitDataBlock(pointer, 38512) == 1: |
|
248 | if self.waitDataBlock(pointer, 38512) == 1: | |
254 | continue |
|
249 | continue | |
255 | else: |
|
250 | else: | |
256 | if not self.setNextFile(): |
|
251 | if not self.setNextFile(): | |
257 | return 0 |
|
252 | return 0 | |
258 |
|
253 | |||
259 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ |
|
254 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ | |
260 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): |
|
255 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): | |
261 | log.warning( |
|
256 | log.warning( | |
262 | 'Reading Record No. {}/{} -> {} [Skipping]'.format( |
|
257 | 'Reading Record No. {}/{} -> {} [Skipping]'.format( | |
263 | self.counter_records, |
|
258 | self.counter_records, | |
264 | self.nrecords, |
|
259 | self.nrecords, | |
265 | self.datatime.ctime()), |
|
260 | self.datatime.ctime()), | |
266 | 'BLTRParamReader') |
|
261 | 'BLTRParamReader') | |
267 | continue |
|
262 | continue | |
268 | break |
|
263 | break | |
269 |
|
264 | |||
270 |
log.log('Reading Record No. {} |
|
265 | log.log('Reading Record No. {} -> {}'.format( | |
271 | self.counter_records, |
|
266 | self.counter_records, | |
272 | self.nrecords, |
|
267 | # self.nrecords, | |
273 | self.datatime.ctime()), 'BLTRParamReader') |
|
268 | self.datatime.ctime()), 'BLTRParamReader') | |
274 |
|
269 | |||
275 | return 1 |
|
270 | return 1 | |
276 |
|
271 | |||
277 | def readBlock(self): |
|
272 | def readBlock(self): | |
278 |
|
273 | |||
279 | pointer = self.fp.tell() |
|
274 | pointer = self.fp.tell() | |
280 | header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) |
|
275 | header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) | |
281 | self.nchannels = int(header_rec['nchan'][0] / 2) |
|
276 | self.nchannels = int(header_rec['nchan'][0] / 2) | |
282 | self.kchan = header_rec['nrxs'][0] |
|
277 | self.kchan = header_rec['nrxs'][0] | |
283 | self.nmodes = header_rec['nmodes'][0] |
|
278 | self.nmodes = header_rec['nmodes'][0] | |
284 | self.nranges = header_rec['nranges'][0] |
|
279 | self.nranges = header_rec['nranges'][0] | |
285 | self.fp.seek(pointer) |
|
280 | self.fp.seek(pointer) | |
286 | self.height = numpy.empty((self.nmodes, self.nranges)) |
|
281 | self.height = numpy.empty((self.nmodes, self.nranges)) | |
287 | self.snr = numpy.empty((self.nmodes, int(self.nchannels), self.nranges)) |
|
282 | self.snr = numpy.empty((self.nmodes, int(self.nchannels), self.nranges)) | |
288 | self.buffer = numpy.empty((self.nmodes, 3, self.nranges)) |
|
283 | self.buffer = numpy.empty((self.nmodes, 3, self.nranges)) | |
289 | self.flagDiscontinuousBlock = 0 |
|
284 | self.flagDiscontinuousBlock = 0 | |
290 |
|
285 | |||
291 | for mode in range(self.nmodes): |
|
286 | for mode in range(self.nmodes): | |
292 | self.readHeader() |
|
287 | self.readHeader() | |
293 | data = self.readData() |
|
288 | data = self.readData() | |
294 | self.height[mode] = (data[0] - self.correction) / 1000. |
|
289 | self.height[mode] = (data[0] - self.correction) / 1000. | |
295 | self.buffer[mode] = data[1] |
|
290 | self.buffer[mode] = data[1] | |
296 | self.snr[mode] = data[2] |
|
291 | self.snr[mode] = data[2] | |
297 |
|
292 | |||
298 | self.counter_records = self.counter_records + self.nmodes |
|
293 | self.counter_records = self.counter_records + self.nmodes | |
299 |
|
294 | |||
300 | return |
|
295 | return | |
301 |
|
296 | |||
302 | def readHeader(self): |
|
297 | def readHeader(self): | |
303 | ''' |
|
298 | ''' | |
304 | RecordHeader of BLTR rawdata file |
|
299 | RecordHeader of BLTR rawdata file | |
305 | ''' |
|
300 | ''' | |
306 |
|
301 | |||
307 | header_structure = numpy.dtype( |
|
302 | header_structure = numpy.dtype( | |
308 | REC_HEADER_STRUCTURE.descr + [ |
|
303 | REC_HEADER_STRUCTURE.descr + [ | |
309 | ('antenna_coord', 'f4', (2, int(self.nchannels))), |
|
304 | ('antenna_coord', 'f4', (2, int(self.nchannels))), | |
310 | ('rx_gains', 'u4', (int(self.nchannels),)), |
|
305 | ('rx_gains', 'u4', (int(self.nchannels),)), | |
311 | ('rx_analysis', 'u4', (int(self.nchannels),)) |
|
306 | ('rx_analysis', 'u4', (int(self.nchannels),)) | |
312 | ] |
|
307 | ] | |
313 | ) |
|
308 | ) | |
314 |
|
309 | |||
315 | self.header_rec = numpy.fromfile(self.fp, header_structure, 1) |
|
310 | self.header_rec = numpy.fromfile(self.fp, header_structure, 1) | |
316 | self.lat = self.header_rec['lat'][0] |
|
311 | self.lat = self.header_rec['lat'][0] | |
317 | self.lon = self.header_rec['lon'][0] |
|
312 | self.lon = self.header_rec['lon'][0] | |
318 | self.delta = self.header_rec['delta_r'][0] |
|
313 | self.delta = self.header_rec['delta_r'][0] | |
319 | self.correction = self.header_rec['dmode_rngcorr'][0] |
|
314 | self.correction = self.header_rec['dmode_rngcorr'][0] | |
320 | self.imode = self.header_rec['dmode_index'][0] |
|
315 | self.imode = self.header_rec['dmode_index'][0] | |
321 | self.antenna = self.header_rec['antenna_coord'] |
|
316 | self.antenna = self.header_rec['antenna_coord'] | |
322 | self.rx_gains = self.header_rec['rx_gains'] |
|
317 | self.rx_gains = self.header_rec['rx_gains'] | |
323 | self.time = self.header_rec['time'][0] |
|
318 | self.time = self.header_rec['time'][0] | |
324 | dt = datetime.datetime.utcfromtimestamp(self.time) |
|
319 | dt = datetime.datetime.utcfromtimestamp(self.time) | |
325 | if dt.date()>self.datatime.date(): |
|
320 | if dt.date()>self.datatime.date(): | |
326 | self.flagDiscontinuousBlock = 1 |
|
321 | self.flagDiscontinuousBlock = 1 | |
327 | self.datatime = dt |
|
322 | self.datatime = dt | |
328 |
|
323 | |||
329 | def readData(self): |
|
324 | def readData(self): | |
330 | ''' |
|
325 | ''' | |
331 |
Reading and filtering data block record of BLTR rawdata file, |
|
326 | Reading and filtering data block record of BLTR rawdata file, | |
|
327 | filtering is according to status_value. | |||
332 |
|
328 | |||
333 | Input: |
|
329 | Input: | |
334 |
status_value - Array data is set to NAN for values that are not |
|
330 | status_value - Array data is set to NAN for values that are not | |
|
331 | equal to status_value | |||
335 |
|
332 | |||
336 | ''' |
|
333 | ''' | |
337 | self.nchannels = int(self.nchannels) |
|
334 | self.nchannels = int(self.nchannels) | |
338 |
|
335 | |||
339 | data_structure = numpy.dtype( |
|
336 | data_structure = numpy.dtype( | |
340 | DATA_STRUCTURE.descr + [ |
|
337 | DATA_STRUCTURE.descr + [ | |
341 | ('rx_saturation', 'u4', (self.nchannels,)), |
|
338 | ('rx_saturation', 'u4', (self.nchannels,)), | |
342 | ('chan_offset', 'u4', (2 * self.nchannels,)), |
|
339 | ('chan_offset', 'u4', (2 * self.nchannels,)), | |
343 | ('rx_amp', 'u4', (self.nchannels,)), |
|
340 | ('rx_amp', 'u4', (self.nchannels,)), | |
344 | ('rx_snr', 'f4', (self.nchannels,)), |
|
341 | ('rx_snr', 'f4', (self.nchannels,)), | |
345 | ('cross_snr', 'f4', (self.kchan,)), |
|
342 | ('cross_snr', 'f4', (self.kchan,)), | |
346 | ('sea_power_relative', 'f4', (self.kchan,))] |
|
343 | ('sea_power_relative', 'f4', (self.kchan,))] | |
347 | ) |
|
344 | ) | |
348 |
|
345 | |||
349 | data = numpy.fromfile(self.fp, data_structure, self.nranges) |
|
346 | data = numpy.fromfile(self.fp, data_structure, self.nranges) | |
350 |
|
347 | |||
351 | height = data['range'] |
|
348 | height = data['range'] | |
352 | winds = numpy.array( |
|
349 | winds = numpy.array( | |
353 | (data['zonal'], data['meridional'], data['vertical'])) |
|
350 | (data['zonal'], data['meridional'], data['vertical'])) | |
354 | snr = data['rx_snr'].T |
|
351 | snr = data['rx_snr'].T | |
355 |
|
352 | |||
356 | winds[numpy.where(winds == -9999.)] = numpy.nan |
|
353 | winds[numpy.where(winds == -9999.)] = numpy.nan | |
357 | winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
354 | winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan | |
358 | snr[numpy.where(snr == -9999.)] = numpy.nan |
|
355 | snr[numpy.where(snr == -9999.)] = numpy.nan | |
359 | snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
356 | snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan | |
360 | snr = numpy.power(10, snr / 10) |
|
357 | snr = numpy.power(10, snr / 10) | |
361 |
|
358 | |||
362 | return height, winds, snr |
|
359 | return height, winds, snr | |
363 |
|
360 | |||
364 | def set_output(self): |
|
361 | def set_output(self): | |
365 | ''' |
|
362 | ''' | |
366 | Storing data from databuffer to dataOut object |
|
363 | Storing data from databuffer to dataOut object | |
367 | ''' |
|
364 | ''' | |
368 |
|
365 | |||
369 | self.dataOut.data_SNR = self.snr |
|
366 | self.dataOut.data_SNR = self.snr | |
370 | self.dataOut.height = self.height |
|
367 | self.dataOut.height = self.height | |
371 | self.dataOut.data = self.buffer |
|
368 | self.dataOut.data = self.buffer | |
372 | self.dataOut.utctimeInit = self.time |
|
369 | self.dataOut.utctimeInit = self.time | |
373 | self.dataOut.utctime = self.dataOut.utctimeInit |
|
370 | self.dataOut.utctime = self.dataOut.utctimeInit | |
374 | self.dataOut.useLocalTime = False |
|
371 | self.dataOut.useLocalTime = False | |
375 | self.dataOut.paramInterval = 157 |
|
372 | self.dataOut.paramInterval = 157 | |
376 | self.dataOut.timezone = self.timezone |
|
373 | self.dataOut.timezone = self.timezone | |
377 | self.dataOut.site = self.siteFile |
|
374 | self.dataOut.site = self.siteFile | |
378 | self.dataOut.nrecords = self.nrecords / self.nmodes |
|
375 | self.dataOut.nrecords = self.nrecords / self.nmodes | |
379 | self.dataOut.sizeOfFile = self.sizeOfFile |
|
376 | self.dataOut.sizeOfFile = self.sizeOfFile | |
380 | self.dataOut.lat = self.lat |
|
377 | self.dataOut.lat = self.lat | |
381 | self.dataOut.lon = self.lon |
|
378 | self.dataOut.lon = self.lon | |
382 | self.dataOut.channelList = list(range(self.nchannels)) |
|
379 | self.dataOut.channelList = list(range(self.nchannels)) | |
383 | self.dataOut.kchan = self.kchan |
|
380 | self.dataOut.kchan = self.kchan | |
384 | self.dataOut.delta = self.delta |
|
381 | self.dataOut.delta = self.delta | |
385 | self.dataOut.correction = self.correction |
|
382 | self.dataOut.correction = self.correction | |
386 | self.dataOut.nmodes = self.nmodes |
|
383 | self.dataOut.nmodes = self.nmodes | |
387 | self.dataOut.imode = self.imode |
|
384 | self.dataOut.imode = self.imode | |
388 | self.dataOut.antenna = self.antenna |
|
385 | self.dataOut.antenna = self.antenna | |
389 | self.dataOut.rx_gains = self.rx_gains |
|
386 | self.dataOut.rx_gains = self.rx_gains | |
390 | self.dataOut.flagNoData = False |
|
387 | self.dataOut.flagNoData = False | |
391 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
388 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |
392 |
|
389 | |||
393 | def getData(self): |
|
390 | def getData(self): | |
394 | ''' |
|
391 | ''' | |
395 | Storing data from databuffer to dataOut object |
|
392 | Storing data from databuffer to dataOut object | |
396 | ''' |
|
393 | ''' | |
397 | if self.flagNoMoreFiles: |
|
394 | if self.flagNoMoreFiles: | |
398 | self.dataOut.flagNoData = True |
|
395 | self.dataOut.flagNoData = True | |
399 | self.dataOut.error = 'No More files to read' |
|
396 | self.dataOut.error = 'No More files to read' | |
400 | return |
|
397 | return | |
401 |
|
398 | |||
402 | if not self.readNextBlock(): |
|
399 | if not self.readNextBlock(): | |
403 | self.dataOut.flagNoData = True |
|
400 | self.dataOut.flagNoData = True | |
404 | self.dataOut.error = 'Time for wait new file reach!!!' |
|
401 | self.dataOut.error = 'Time for wait new file reach!!!' | |
405 |
|
402 | |||
406 | self.set_output() |
|
403 | self.set_output() | |
407 |
|
404 | |||
408 | return 1 |
|
405 | return 1 | |
409 | No newline at end of file |
|
406 |
General Comments 0
You need to be logged in to leave comments.
Login now