From 7695222b742187aeb5dce66e1d60980169e54b6c Mon Sep 17 00:00:00 2001 From: Yann Forget Date: Thu, 19 Dec 2024 12:37:42 +0100 Subject: [PATCH] feat(era5): support hours as download parameter (#73) --- openhexa/toolbox/era5/cds.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/openhexa/toolbox/era5/cds.py b/openhexa/toolbox/era5/cds.py index 6947b8e..e4d7c78 100644 --- a/openhexa/toolbox/era5/cds.py +++ b/openhexa/toolbox/era5/cds.py @@ -112,7 +112,6 @@ def get_period_chunk(dtimes: list[datetime]) -> dict: "year": str(year), "month": f"{month:02}", "day": [f"{day:02}" for day in days], - "time": [f"{hour:02}:00" for hour in range(24)], } @@ -347,7 +346,13 @@ def retrieve(self, request: DataRequest, dst_file: Path | str) -> None: self.client.retrieve(collection_id=DATASET, target=dst_file, **request.__dict__) def download_between( - self, start: datetime, end: datetime, variable: str, area: list[float], dst_dir: str | Path + self, + start: datetime, + end: datetime, + variable: str, + area: list[float], + dst_dir: str | Path, + time: list[int] | None = None, ) -> None: """Download all ERA5 data files needed to cover the period. @@ -366,6 +371,8 @@ def download_between( Area of interest (north, west, south, east). dst_dir : str | Path Output directory. + time : list[int] | None, optional + Hours of interest (ex: [1, 6, 18]). Defaults to None (all hours). """ dst_dir = Path(dst_dir) dst_dir.mkdir(parents=True, exist_ok=True) @@ -392,7 +399,7 @@ def download_between( remotes: list[Remote] = [] for chunk in iter_chunks(dates): - request = build_request(variable=variable, data_format="grib", area=area, **chunk) + request = build_request(variable=variable, data_format="grib", area=area, time=time, **chunk) # has a similar request been submitted recently? if yes, use it instead of submitting # a new one