diff --git a/forest/drivers/eida50.py b/forest/drivers/eida50.py index b707768b..5c007cf3 100644 --- a/forest/drivers/eida50.py +++ b/forest/drivers/eida50.py @@ -25,12 +25,12 @@ def _natargmax(arr): class Dataset: - def __init__(self, pattern=None, database_path=None, **kwargs): + def __init__(self, pattern=None, database_path=None, minutes=15, **kwargs): self.pattern = pattern if database_path is None: database_path = ":memory:" self.database = Database(database_path) - self.locator = Locator(self.pattern, self.database) + self.locator = Locator(self.pattern, self.database, minutes=minutes) def navigator(self): return Navigator(self.locator, self.database) @@ -133,9 +133,12 @@ def fetch_paths(self): class Locator: """Locate EIDA50 satellite images""" - def __init__(self, pattern, database): + def __init__(self, pattern, database, minutes=15): + self.minutes = minutes self.pattern = pattern - self._glob = forest.util.cached_glob(dt.timedelta(minutes=15)) + self._glob = forest.util.cached_glob( + dt.timedelta(minutes=self.minutes) + ) self.database = database def all_times(self, paths): @@ -183,7 +186,9 @@ def find(self, paths, date): else: times = self.load_time_axis(path) # datetime64[s] - index = self.find_index(times, date, dt.timedelta(minutes=15)) + index = self.find_index( + times, date, dt.timedelta(minutes=self.minutes) + ) return path, index def glob(self): @@ -219,6 +224,7 @@ def find_file(self, paths, user_date): @staticmethod def find_index(times, time, length): """Search for index inside array of datetime64[s] values""" + print(f"FIND_INDEX: {times} {time} {length}") dtype = "datetime64[s]" if isinstance(times, list): times = np.asarray(times, dtype=dtype) @@ -271,7 +277,8 @@ def image(self, state): else: try: data = self._image(forest.util.to_datetime(state.valid_time)) - except (FileNotFound, IndexNotFound): + except (FileNotFound, IndexNotFound) as e: + print(f"EIDA50: {e}") data = self.empty_image return data diff --git a/forest/drivers/unified_model.py b/forest/drivers/unified_model.py index 4520d9d8..308ff168 100644 --- a/forest/drivers/unified_model.py +++ b/forest/drivers/unified_model.py @@ -200,24 +200,28 @@ def __init__(self, pattern): "pressure": PressuresLocator(), } - def variables(self, pattern): - cubes = iris.load(pattern) + def variables(self, _pattern): + cubes = iris.load(self.pattern) return [cube.name() for cube in cubes] - def initial_times(self, pattern, variable): + def initial_times(self, _pattern, variable): locator = self._locators["initial"] - return list(sorted(set(locator(path) for path in glob.glob(pattern)))) + return list( + sorted(set(locator(path) for path in glob.glob(self.pattern))) + ) - def valid_times(self, pattern, variable, initial_time): - return self._dimension("valid", pattern, variable, initial_time) + def valid_times(self, _pattern, variable, initial_time): + return self._dimension("valid", self.pattern, variable, initial_time) - def pressures(self, pattern, variable, initial_time): - return self._dimension("pressure", pattern, variable, initial_time) + def pressures(self, _pattern, variable, initial_time): + return self._dimension( + "pressure", self.pattern, variable, initial_time + ) def _dimension(self, keyword, pattern, variable, initial_time): arrays = [] locator = self._locators[keyword] - for path in glob.glob(self.pattern): + for path in glob.glob(pattern): arrays.append(locator(path, variable)) if len(arrays) == 0: return []