From d7dbd8c167a4e2751346b2284008e5bb5cf3e8f3 Mon Sep 17 00:00:00 2001 From: tomrink <rink@ssec.wisc.edu> Date: Tue, 2 Jul 2024 11:49:33 -0500 Subject: [PATCH] snapshot... --- modules/aeolus/datasource.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/aeolus/datasource.py b/modules/aeolus/datasource.py index 66a785b4..9908da8a 100644 --- a/modules/aeolus/datasource.py +++ b/modules/aeolus/datasource.py @@ -110,9 +110,17 @@ class Files: self._current_index = 0 def get_datetime(self, pathname): + """ + :param pathname: The full-path of the file. + :return: The file's time label as a datetime object. + """ pass def get_file_containing_time(self, timestamp): + """ + :param timestamp: seconds since the epoch + :return: the file whose time range (defined as the difference between consecutive file time labels) contains timestamp. + """ k = -1 for i in range(self.ftimes.shape[0]): if (timestamp >= self.ftimes[i, 0]) and (timestamp < self.ftimes[i, 1]): @@ -124,6 +132,11 @@ class Files: return self.flist[k], self.ftimes[k, 0], k def get_file(self, timestamp, window=None): + """ + :param timestamp: seconds since the epoch. + :param window: the duration of files in this object. Defaults to the constructor time span. + :return: the file whose duration contains the timestamp. + """ if window is None: window = self.span_seconds else: @@ -135,6 +148,22 @@ class Files: else: return None, None, None + def get_file_in_range(self, timestamp, t_lo_minutes, t_hi_minutes): + """ + :param timestamp: + :param t_lo_minutes: can be negative or positive + :param t_hi_minutes: can be negative or positive, but must be greater than t_lo_minutes. + :return: the file whose time label is within the absolute range (timestamp + t_lo_minutes, timestamp + t_hi_minutes) + """ + + t_lo = timestamp + datetime.timedelta(minutes=t_lo_minutes).seconds + t_hi = timestamp + datetime.timedelta(minutes=t_hi_minutes).seconds + + midx = np.where(np.logical_and(self.ftimes[:, 0] >= t_lo, self.ftimes[:, 0] < t_hi))[0] + midx = midx[0] # the first occurrence + + return self.flist[midx], self.ftimes[midx, 0], midx + def get_parameters(self): pass -- GitLab