From d383cdcd331ab763c3e1ca51962a69846e4af820 Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Thu, 3 Dec 2020 11:56:35 -0600 Subject: [PATCH] snapshot... --- modules/aeolus/aeolus_amv.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/aeolus/aeolus_amv.py b/modules/aeolus/aeolus_amv.py index 0842f98c..ce42ef77 100644 --- a/modules/aeolus/aeolus_amv.py +++ b/modules/aeolus/aeolus_amv.py @@ -28,7 +28,8 @@ class AMVFiles: self.flist = glob.glob(files_path + pattern) self.band = band self.ftimes = [] - for pname in self.flist: # TODO: make better with regular expressions (someday) + self.span_seconds = datetime.timedelta(minutes=file_time_span).seconds + for pname in self.flist: dto = self.get_datetime(pname) dto_start = dto dto_end = dto + datetime.timedelta(minutes=file_time_span) @@ -47,14 +48,22 @@ class AMVFiles: def get_file_containing_time(self, timestamp): k = -1 - for i in range(len(self.ftimes)): - if (timestamp >= self.ftimes[i][0]) and (timestamp < self.ftimes[i][1]): + for i in range(len(self.ftimes.shape[0])): + if (timestamp >= self.ftimes[i, 0]) and (timestamp < self.ftimes[i, 1]): k = i break if k < 0: return None, None, None - return self.flist[k], self.ftimes[k], k + return self.flist[k], self.ftimes[k, 0], k + + def get_file(self, timestamp): + diff = self.ftimes[:, 0] - timestamp + midx = np.argmin(np.abs(diff)) + if np.abs(self.ftimes[midx, 0] - timestamp) < self.span_seconds: + return self.flist[midx], self.ftimes[midx, 0], midx + else: + return None, None, None def get_parameters(self): pass @@ -172,7 +181,7 @@ def match_amvs_to_raobs(raob_dict, raob_time, amv_files, filepath=None): match_dict = {} if filepath is None: - filepath, ftime, f_idx = amv_files.get_file_containing_time(raob_time) + filepath, ftime, f_idx = amv_files.get_file(raob_time) ds = Dataset(filepath) -- GitLab