Skip to content

Commit

Permalink
better error message (#146)
Browse files Browse the repository at this point in the history
* better error message
  • Loading branch information
b8raoult authored Dec 2, 2024
1 parent a36f01c commit 9cb1768
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/anemoi/datasets/create/input/repeated_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def transform(self, group_of_dates):
end += self.frequency

to_try = sorted(to_try - self.tried)
info = {k: "no-data" for k in to_try}

if not to_try:
LOG.warning(f"No new dates to try for {group_of_dates} in {self.source}")
# return []

if to_try:
result = self.source.select(
Expand All @@ -82,19 +87,32 @@ def transform(self, group_of_dates):
)
)

cnt = 0
for f in result.datasource:
cnt += 1
# We could keep the fields in a dictionary, but we don't want to keep the fields in memory
date = as_datetime(f.metadata("valid_datetime"))

if self.skip_all_nans:
if np.isnan(f.to_numpy()).all():
LOG.warning(f"Skipping {date} because all values are NaN")
info[date] = "all-nans"
continue

info[date] = "ok"
self.found.add(date)

if cnt == 0:
raise ValueError(f"No data found for {group_of_dates} in {self.source}")

self.tried.update(to_try)

if not self.found:
for k, v in info.items():
LOG.warning(f"{k}: {v}")

raise ValueError(f"No matching data found for {asked_dates} in {self.source}")

new_dates = defaultdict(list)

for date in asked_dates:
Expand Down

0 comments on commit 9cb1768

Please sign in to comment.