@@ -1305,7 +1305,7 class PlotterData(object): | |||
|
1305 | 1305 | for key in self.data: |
|
1306 | 1306 | shape = self.shape(key)[:-1] + H.shape |
|
1307 | 1307 | for tm, obj in list(self.data[key].items()): |
|
1308 | h = self.__heights[self.times.index(tm)] | |
|
1308 | h = self.__heights[self.times.tolist().index(tm)] | |
|
1309 | 1309 | if H.size == h.size: |
|
1310 | 1310 | continue |
|
1311 | 1311 | index = numpy.where(numpy.in1d(H, h))[0] |
@@ -142,6 +142,11 class ParametersPlot(RTIPlot): | |||
|
142 | 142 | self.ncols = 1 |
|
143 | 143 | self.nrows = self.data.shape(self.CODE)[0] |
|
144 | 144 | self.nplots = self.nrows |
|
145 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95}) | |
|
146 | ||
|
147 | if not self.xlabel: | |
|
148 | self.xlabel = 'Time' | |
|
149 | ||
|
145 | 150 | if self.showSNR: |
|
146 | 151 | self.nrows += 1 |
|
147 | 152 | self.nplots += 1 |
@@ -16,7 +16,7 import numpy | |||
|
16 | 16 | import schainpy.admin |
|
17 | 17 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator |
|
18 | 18 | from schainpy.model.data.jrodata import Parameters |
|
19 |
from schainpy.model.io.jroIO_base import |
|
|
19 | from schainpy.model.io.jroIO_base import Reader | |
|
20 | 20 | from schainpy.utils import log |
|
21 | 21 | |
|
22 | 22 | FILE_HEADER_STRUCTURE = numpy.dtype([ |
@@ -85,7 +85,7 DATA_STRUCTURE = numpy.dtype([ | |||
|
85 | 85 | ]) |
|
86 | 86 | |
|
87 | 87 | |
|
88 |
class BLTRParamReader( |
|
|
88 | class BLTRParamReader(Reader, ProcessingUnit): | |
|
89 | 89 | ''' |
|
90 | 90 | Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR |
|
91 | 91 | from *.sswma files |
@@ -98,143 +98,84 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
98 | 98 | ProcessingUnit.__init__(self) |
|
99 | 99 | |
|
100 | 100 | self.dataOut = Parameters() |
|
101 | self.dataOut.timezone = 300 | |
|
101 | 102 | self.counter_records = 0 |
|
102 | 103 | self.flagNoMoreFiles = 0 |
|
103 | 104 | self.isConfig = False |
|
104 | 105 | self.filename = None |
|
105 | ||
|
106 | def setup(self, | |
|
107 | path=None, | |
|
108 | startDate=None, | |
|
109 | endDate=None, | |
|
110 | ext=None, | |
|
111 | startTime=datetime.time(0, 0, 0), | |
|
112 | endTime=datetime.time(23, 59, 59), | |
|
113 | timezone=0, | |
|
114 | status_value=0, | |
|
115 | **kwargs): | |
|
116 | self.path = path | |
|
117 | self.startDate = startDate | |
|
118 | self.endDate = endDate | |
|
119 | self.startTime = startTime | |
|
120 | self.endTime = endTime | |
|
121 | self.status_value = status_value | |
|
106 | self.status_value = 0 | |
|
122 | 107 | self.datatime = datetime.datetime(1900,1,1) |
|
123 | self.delay = kwargs.get('delay', 10) | |
|
124 | self.online = kwargs.get('online', False) | |
|
125 | self.nTries = kwargs.get('nTries', 3) | |
|
108 | self.filefmt = "*********%Y%m%d******" | |
|
126 | 109 | |
|
127 | if self.path is None: | |
|
128 | raise ValueError("The path is not valid") | |
|
110 | def setup(self, **kwargs): | |
|
129 | 111 | |
|
130 | if ext is None: | |
|
131 | ext = self.ext | |
|
112 | self.set_kwargs(**kwargs) | |
|
132 | 113 | |
|
133 | self.fileList = self.search_files(self.path, startDate, endDate, ext) | |
|
134 | self.timezone = timezone | |
|
135 | self.fileIndex = 0 | |
|
114 | if self.path is None: | |
|
115 | raise ValueError("The path is not valid") | |
|
136 | 116 | |
|
137 |
if |
|
|
138 | raise Warning("There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % ( | |
|
139 | path)) | |
|
117 | if self.online: | |
|
118 | log.log("Searching files in online mode...", self.name) | |
|
140 | 119 | |
|
141 | self.setNextFile() | |
|
120 | for nTries in range(self.nTries): | |
|
121 | fullpath = self.searchFilesOnLine(self.path, self.startDate, | |
|
122 | self.endDate, self.expLabel, self.ext, self.walk, | |
|
123 | self.filefmt, self.folderfmt) | |
|
124 | try: | |
|
125 | fullpath = next(fullpath) | |
|
126 | except: | |
|
127 | fullpath = None | |
|
142 | 128 | |
|
143 | def search_last_file(self): | |
|
144 | ''' | |
|
145 | Get last file and add it to the list | |
|
146 | ''' | |
|
129 | if fullpath: | |
|
130 | self.fileSize = os.path.getsize(fullpath) | |
|
131 | self.filename = fullpath | |
|
132 | self.flagIsNewFile = 1 | |
|
133 | if self.fp != None: | |
|
134 | self.fp.close() | |
|
135 | self.fp = self.open_file(fullpath, self.open_mode) | |
|
136 | self.flagNoMoreFiles = 0 | |
|
137 | break | |
|
147 | 138 | |
|
148 | for n in range(self.nTries+1): | |
|
149 | if n>0: | |
|
150 | 139 | log.warning( |
|
151 |
|
|
|
152 |
self. |
|
|
153 | ) | |
|
140 | 'Waiting {} sec for a valid file in {}: try {} ...'.format( | |
|
141 | self.delay, self.path, nTries + 1), | |
|
142 | self.name) | |
|
154 | 143 | time.sleep(self.delay) |
|
155 | file_list = os.listdir(self.path) | |
|
156 | file_list.sort() | |
|
157 | if file_list: | |
|
158 | if self.filename: | |
|
159 | if file_list[-1] not in self.filename: | |
|
160 | return file_list[-1] | |
|
144 | ||
|
145 | if not(fullpath): | |
|
146 | raise schainpy.admin.SchainError( | |
|
147 | 'There isn\'t any valid file in {}'.format(self.path)) | |
|
148 | self.readFirstHeader() | |
|
161 | 149 |
|
|
162 | continue | |
|
163 | return file_list[-1] | |
|
164 | return 0 | |
|
150 | log.log("Searching files in {}".format(self.path), self.name) | |
|
151 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, | |
|
152 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) | |
|
153 | self.setNextFile() | |
|
165 | 154 | |
|
166 | def search_files(self, path, startDate, endDate, ext): | |
|
155 | def checkForRealPath(self, nextFile, nextDay): | |
|
167 | 156 | ''' |
|
168 | Searching for BLTR rawdata file in path | |
|
169 | Creating a list of file to proces included in [startDate,endDate] | |
|
170 | ||
|
171 | Input: | |
|
172 | path - Path to find BLTR rawdata files | |
|
173 | startDate - Select file from this date | |
|
174 | enDate - Select file until this date | |
|
175 | ext - Extension of the file to read | |
|
176 | 157 | ''' |
|
177 | 158 | |
|
178 | log.success('Searching files in {} '.format(path), 'BLTRParamReader') | |
|
179 | foldercounter = 0 | |
|
180 | fileList0 = glob.glob1(path, "*%s" % ext) | |
|
181 | fileList0.sort() | |
|
182 | ||
|
183 | for thisFile in fileList0: | |
|
184 | year = thisFile[-14:-10] | |
|
185 | if not isNumber(year): | |
|
186 | continue | |
|
187 | ||
|
188 | month = thisFile[-10:-8] | |
|
189 | if not isNumber(month): | |
|
190 | continue | |
|
191 | ||
|
192 | day = thisFile[-8:-6] | |
|
193 | if not isNumber(day): | |
|
194 | continue | |
|
195 | ||
|
196 | year, month, day = int(year), int(month), int(day) | |
|
197 | dateFile = datetime.date(year, month, day) | |
|
198 | ||
|
199 | if (startDate > dateFile) or (endDate < dateFile): | |
|
200 | continue | |
|
201 | ||
|
202 | yield thisFile | |
|
203 | ||
|
204 | return | |
|
159 | dt = self.datatime + datetime.timedelta(1) | |
|
160 | filename = '{}.{}{}'.format(self.siteFile, dt.strftime('%Y%m%d'), self.ext) | |
|
161 | fullfilename = os.path.join(self.path, filename) | |
|
162 | if os.path.exists(fullfilename): | |
|
163 | return fullfilename, filename | |
|
164 | return None, filename | |
|
205 | 165 | |
|
206 | def setNextFile(self): | |
|
207 | 166 | |
|
208 | if self.online: | |
|
209 | filename = self.search_last_file() | |
|
210 | if not filename: | |
|
211 | self.flagNoMoreFiles = 1 | |
|
212 | return 0 | |
|
213 | else: | |
|
214 | try: | |
|
215 | filename = next(self.fileList) | |
|
216 | except StopIteration: | |
|
217 | self.flagNoMoreFiles = 1 | |
|
218 | return 0 | |
|
219 | ||
|
220 | log.success('Opening {}'.format(filename), 'BLTRParamReader') | |
|
167 | def readFirstHeader(self): | |
|
168 | ''' | |
|
169 | ''' | |
|
221 | 170 | |
|
222 | dirname, name = os.path.split(filename) | |
|
223 | 171 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya |
|
224 | self.siteFile = filename.split('.')[0] | |
|
225 | if self.filename is not None: | |
|
226 | self.fp.close() | |
|
227 | self.filename = os.path.join(self.path, filename) | |
|
228 | self.fp = open(self.filename, 'rb') | |
|
172 | self.siteFile = self.filename.split('/')[-1].split('.')[0] | |
|
229 | 173 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) |
|
230 | 174 | self.nrecords = self.header_file['nrec'][0] |
|
231 | self.sizeOfFile = os.path.getsize(self.filename) | |
|
232 | 175 | self.counter_records = 0 |
|
233 | 176 | self.flagIsNewFile = 0 |
|
234 | 177 | self.fileIndex += 1 |
|
235 | 178 | |
|
236 | return 1 | |
|
237 | ||
|
238 | 179 | def readNextBlock(self): |
|
239 | 180 | |
|
240 | 181 | while True: |
@@ -242,7 +183,6 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
242 | 183 | self.flagIsNewFile = 1 |
|
243 | 184 | if not self.setNextFile(): |
|
244 | 185 | return 0 |
|
245 | ||
|
246 | 186 | try: |
|
247 | 187 | pointer = self.fp.tell() |
|
248 | 188 | self.readBlock() |
@@ -266,7 +206,6 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
266 | 206 | |
|
267 | 207 | log.log('Reading Record No. {} -> {}'.format( |
|
268 | 208 | self.counter_records, |
|
269 | # self.nrecords, | |
|
270 | 209 | self.datatime.ctime()), 'BLTRParamReader') |
|
271 | 210 | |
|
272 | 211 | return 1 |
@@ -372,10 +311,8 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
372 | 311 | self.dataOut.utctime = self.dataOut.utctimeInit |
|
373 | 312 | self.dataOut.useLocalTime = False |
|
374 | 313 | self.dataOut.paramInterval = 157 |
|
375 | self.dataOut.timezone = self.timezone | |
|
376 | 314 | self.dataOut.site = self.siteFile |
|
377 | 315 | self.dataOut.nrecords = self.nrecords / self.nmodes |
|
378 | self.dataOut.sizeOfFile = self.sizeOfFile | |
|
379 | 316 | self.dataOut.lat = self.lat |
|
380 | 317 | self.dataOut.lon = self.lon |
|
381 | 318 | self.dataOut.channelList = list(range(self.nchannels)) |
@@ -395,13 +332,24 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
395 | 332 | ''' |
|
396 | 333 | if self.flagNoMoreFiles: |
|
397 | 334 | self.dataOut.flagNoData = True |
|
398 | raise schainpy.admin.SchainError('No More files to read') | |
|
335 | return 0 | |
|
399 | 336 | |
|
400 | 337 | if not self.readNextBlock(): |
|
401 | 338 | self.dataOut.flagNoData = True |
|
402 | raise schainpy.admin.SchainError('Time for wait new file reach!!!') | |
|
339 | return 0 | |
|
403 | 340 | |
|
404 | 341 | self.set_output() |
|
405 | 342 | |
|
406 | 343 | return 1 |
|
407 | 344 | |
|
345 | def run(self, **kwargs): | |
|
346 | ''' | |
|
347 | ''' | |
|
348 | ||
|
349 | if not(self.isConfig): | |
|
350 | self.setup(**kwargs) | |
|
351 | self.isConfig = True | |
|
352 | ||
|
353 | self.getData() | |
|
354 | ||
|
355 | return No newline at end of file |
@@ -717,6 +717,35 class Reader(object): | |||
|
717 | 717 | |
|
718 | 718 | pass |
|
719 | 719 | |
|
720 | def waitDataBlock(self, pointer_location, blocksize=None): | |
|
721 | """ | |
|
722 | """ | |
|
723 | ||
|
724 | currentPointer = pointer_location | |
|
725 | if blocksize is None: | |
|
726 | neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize | |
|
727 | else: | |
|
728 | neededSize = blocksize | |
|
729 | ||
|
730 | for nTries in range(self.nTries): | |
|
731 | self.fp.close() | |
|
732 | self.fp = open(self.filename, 'rb') | |
|
733 | self.fp.seek(currentPointer) | |
|
734 | ||
|
735 | self.fileSize = os.path.getsize(self.filename) | |
|
736 | currentSize = self.fileSize - currentPointer | |
|
737 | ||
|
738 | if (currentSize >= neededSize): | |
|
739 | return 1 | |
|
740 | ||
|
741 | log.warning( | |
|
742 | "Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1), | |
|
743 | self.name | |
|
744 | ) | |
|
745 | time.sleep(self.delay) | |
|
746 | ||
|
747 | return 0 | |
|
748 | ||
|
720 | 749 | class JRODataReader(Reader): |
|
721 | 750 | |
|
722 | 751 | utc = 0 |
@@ -828,33 +857,6 class JRODataReader(Reader): | |||
|
828 | 857 | |
|
829 | 858 | return 0 |
|
830 | 859 | |
|
831 | def waitDataBlock(self, pointer_location, blocksize=None): | |
|
832 | ||
|
833 | currentPointer = pointer_location | |
|
834 | if blocksize is None: | |
|
835 | neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize | |
|
836 | else: | |
|
837 | neededSize = blocksize | |
|
838 | ||
|
839 | for nTries in range(self.nTries): | |
|
840 | self.fp.close() | |
|
841 | self.fp = open(self.filename, 'rb') | |
|
842 | self.fp.seek(currentPointer) | |
|
843 | ||
|
844 | self.fileSize = os.path.getsize(self.filename) | |
|
845 | currentSize = self.fileSize - currentPointer | |
|
846 | ||
|
847 | if (currentSize >= neededSize): | |
|
848 | return 1 | |
|
849 | ||
|
850 | log.warning( | |
|
851 | "Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1), | |
|
852 | self.name | |
|
853 | ) | |
|
854 | time.sleep(self.delay) | |
|
855 | ||
|
856 | return 0 | |
|
857 | ||
|
858 | 860 | def __setNewBlock(self): |
|
859 | 861 | |
|
860 | 862 | if self.fp == None: |
General Comments 0
You need to be logged in to leave comments.
Login now