From 49657ebe0b009955091f186ad546881f67cfa80c Mon Sep 17 00:00:00 2001 From: Alan De Smet <alan.desmet@ssec.wisc.edu> Date: Mon, 16 Aug 2021 21:21:06 +0000 Subject: [PATCH] aitf.ancil.GFS needs custom get_cachefilesets --- example/aitf/ancil.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/example/aitf/ancil.py b/example/aitf/ancil.py index d25ca4f..910571d 100644 --- a/example/aitf/ancil.py +++ b/example/aitf/ancil.py @@ -5,6 +5,7 @@ import sys import datetime as dt sys.path.append(os.path.abspath('..')) import csppfetch +import csppfetch.daterange from csppfetch.roundtozero import roundtozero ################################################################################ @@ -104,6 +105,34 @@ class GFSDownloader(csppfetch.Downloader): local = self._expand(self.local, time, hours_str) return {url:local} + def get_cache_filesets(self, start = None, end = None): + + # A copy of Downloader's implementation, but we don't use + # self._daterange; we call daterange.daterange directly so we can pass + # in a step of self.forecast_step instead of self.period. We do this + # because although our period is only every 6 hours, we change which + # files someone might want every _3_. That is to process 5Z data, we'd + # use the 0Z GFS data's 3 and 6 hour forecasts, but for 7Z data, we'd + # use the 0Z GFS data's 6 and 9 hour forecasts. + # + # Perhaps the ablity to override the period here should be in the + # parent class? Or maybe this case is too specialized to bother. + + if self.oldest_cache < dt.timedelta(days=0): + raise ValueError(f"oldest_cache should be positive; it is {self.oldest_cache}") + + if end is None: end = dt.datetime.now() + if start is None: start = end - self.oldest_cache + + if start > end: + raise ValueError(f"start ({start}) should be before end ({end})") + + fileset_list_list = [] + for time in csppfetch.daterange.daterange(end, start, -self.forecast_step, inclusive=True): + fileset_list = self.get_filesets_for_time(time) + fileset_list_list.append(fileset_list) + return fileset_list_list + def get_filesets_for_time(self, scan_time): generated_time = self._nearest_preceeding_time(scan_time) time_since_gen = scan_time - generated_time -- GitLab