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

feat(era5): support hours as download parameter #73

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading