Skip to content

Commit

Permalink
replace assert with warning when accumulations get negative values
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankrb committed May 17, 2024
1 parent 5796923 commit 096a16d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/anemoi/datasets/create/functions/sources/accumulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# nor does it submit to any jurisdiction.
#
import datetime
import logging
import warnings
from copy import deepcopy

Expand All @@ -18,7 +19,7 @@

from anemoi.datasets.create.utils import to_datetime_list

DEBUG = True
LOG = logging.getLogger(__name__)


def member(field):
Expand Down Expand Up @@ -73,7 +74,10 @@ def check(self, field):
def write(self, template):

assert self.startStep != self.endStep, (self.startStep, self.endStep)
assert np.all(self.values >= 0), (np.amin(self.values), np.amax(self.values))
if np.all(self.values < 0):
LOG.warning(
f"Negative values when computing accumutation for {self.param} ({self.date} {self.time}): min={np.amin(self.values)} max={np.amax(self.values)}"
)

self.out.write(
self.values,
Expand Down Expand Up @@ -432,6 +436,5 @@ def accumulations(context, dates, **request):
dates = yaml.safe_load("[2022-12-30 18:00, 2022-12-31 00:00, 2022-12-31 06:00, 2022-12-31 12:00]")
dates = to_datetime_list(dates)

DEBUG = True
for f in accumulations(None, dates, **config):
print(f, f.to_numpy().mean())

0 comments on commit 096a16d

Please sign in to comment.