From c58111731abf524e782e8d3e548cdae52690db5b Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Tue, 2 Jul 2024 14:34:55 -0500
Subject: [PATCH] snapshot...

---
 modules/aeolus/datasource.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/modules/aeolus/datasource.py b/modules/aeolus/datasource.py
index 9908da8a..17b28e05 100644
--- a/modules/aeolus/datasource.py
+++ b/modules/aeolus/datasource.py
@@ -119,7 +119,7 @@ class Files:
     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.
+        :return: the file whose time range contains timestamp.
         """
         k = -1
         for i in range(self.ftimes.shape[0]):
@@ -134,7 +134,7 @@ class Files:
     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.
+        :param window: the duration (minutes) of files in this object. Defaults to the constructor time span.
         :return: the file whose duration contains the timestamp.
         """
         if window is None:
@@ -154,15 +154,21 @@ class Files:
         :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)
+        if more than one, return the first occurrence.
         """
 
+        if t_hi_minutes <= t_lo_minutes:
+            raise ValueError('t_hi_minutes must be greater than t_lo_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
+        m_idx = np.where(np.logical_and(self.ftimes[:, 0] >= t_lo, self.ftimes[:, 0] < t_hi))[0]
+        if len(m_idx) > 0:
+            m_idx = m_idx[0]  # the first occurrence
+            return self.flist[m_idx], self.ftimes[m_idx, 0], m_idx
+        else:
+            return None, None, None
 
     def get_parameters(self):
         pass
-- 
GitLab