Skip to content

Commit

Permalink
feat(era5): support hours as download parameter (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannforget authored Dec 19, 2024
1 parent a652fe3 commit 7695222
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions openhexa/toolbox/era5/cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
}


Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 7695222

Please sign in to comment.