Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lastest function get error during UTC 0:00-1:12 #51

Open
eldertiger opened this issue Aug 2, 2024 · 0 comments
Open

lastest function get error during UTC 0:00-1:12 #51

eldertiger opened this issue Aug 2, 2024 · 0 comments

Comments

@eldertiger
Copy link

I'm in UTC+8, so this morning at 9:00 when I use the following code to get the latest ecmwf forecast run,

from ecmwf.opendata import Client
latest_time =Client().latest(type='fc'))

I get a wrong message:

Cannot establish latest date for {'date': ['2024-08-01 18:00:00'], 'model': ['ifs'], 'resol': ['0p25'], 'stream': ['oper'], 'type': ['fc'], 'step': ['0'], '_url': ['https://data.ecmwf.int/forecasts']}

I take a look at the client.py and full_date function in date.py, I think the reason comes from the search only end at the last UTC 18z instead of the last UTC 12z. Why not search to the yeasterday UTC 12z, it always pops out when the url get a positive response, so add another time for search won't do harm? the ECMWF forecast comes out at UTC 7:55,13:12,19:55,1:12 for 00/16/12/18.
Maybe change the client.py line to stop = date - datetime.timedelta(days=1, hours=12) or date>=stop ?

def latest(self, request=None, **kwargs):
       if request is None:
           params = dict(**kwargs)
       else:
           params = dict(**request)
       if "time" not in params:
           delta = datetime.timedelta(hours=6)
       else:
           delta = datetime.timedelta(days=1)
       date = full_date(0, params.get("time", 18))
       stop = date - datetime.timedelta(days=1, hours=6)
       while date > stop:
           result = self._get_urls(
               request=None,
               use_index=False,
               date=date,
               **params,
           )
           codes = [
               robust(self.session.head)(url, verify=self.verify).status_code
               for url in result.urls
           ]
           if len(codes) > 0 and all(c == 200 for c in codes):
               return date
           date -= delta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant