Skip to content

Commit

Permalink
Set accumulated values to zero for first time step
Browse files Browse the repository at this point in the history
  • Loading branch information
trygveasp committed Jan 9, 2025
1 parent 5a26332 commit 8030f6c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pysurfex/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def read_variable(self, geo, validtime, cache=None):
"""
# Set variable info
previous_field = None
first_time = False
if self.accumulated:
# Re-read field
previoustime = validtime - as_timedelta(seconds=self.interval)
Expand All @@ -408,14 +409,24 @@ def read_variable(self, geo, validtime, cache=None):
cache=cache,
)
else:
first_time = True
previous_field = np.zeros([geo.npoints])
elif self.instant > 0:
previous_field = np.zeros([geo.npoints])

field = self.read_var_points(self.file_var, geo, validtime=validtime, cache=cache)
deaccumulate = False
if self.accumulated or self.instant > 0:
deaccumulate = True

# Always set accumulated values to zero the first time
if first_time:
deaccumulate = False
field = np.zeros([geo.npoints])
else:
field = self.read_var_points(self.file_var, geo, validtime=validtime, cache=cache)

# Deaccumulate if either two files are read or if instant is > 0.
if self.accumulated or self.instant > 0:
if deaccumulate:
field = self.deaccumulate(field, previous_field, self.instant)
if any(field[field < 0.0]):
raise RuntimeError(
Expand Down

0 comments on commit 8030f6c

Please sign in to comment.