Ejemplo n.º 1
0
 def find_file_index(self, paths, date):
     dates = np.array([self.parse_date(path) for path in paths],
                      dtype='datetime64[s]')
     mask = ~(dates <= date)
     if mask.all():
         msg = "No file for {}".format(date)
         raise FileNotFound(msg)
     before_dates = np.ma.array(dates, mask=mask, dtype='datetime64[s]')
     return np.ma.argmax(before_dates)
Ejemplo n.º 2
0
 def find_file(self, valid_date):
     paths = np.array(self.paths)  # Note: timeout cache in use)
     bounds = locate.bounds(self.dates(paths), dt.timedelta(minutes=15))
     pts = locate.in_bounds(bounds, valid_date)
     found = paths[pts]
     if len(found) > 0:
         return found[0]
     else:
         raise FileNotFound("RDT: '{}' not found in {}".format(
             valid_date, bounds))
Ejemplo n.º 3
0
    def find_file(self, paths, user_date):
        """ "Find file likely to contain user supplied date

        .. note:: Search based on timestamp only

        .. warning:: Not suitable for searching unparsable file names
        """
        if isinstance(user_date, (dt.datetime, str)):
            user_date = np.datetime64(user_date, "s")
        dates = np.array([self.parse_date(path) for path in paths],
                         dtype="datetime64[s]")
        mask = ~(dates <= user_date)
        if mask.all():
            msg = "No file for {}".format(user_date)
            raise FileNotFound(msg)
        before_dates = np.ma.array(dates, mask=mask, dtype="datetime64[s]")
        i = _natargmax(before_dates.filled())
        return paths[i]