Skip to content

Commit

Permalink
Implemented a reset of the states and params to allow for multiple fo…
Browse files Browse the repository at this point in the history
…recast runs in a row
  • Loading branch information
sidekock committed Oct 31, 2024
1 parent 2543683 commit 37739de
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pysteps/nowcasts/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,20 @@ def _measure_time(self, label, start_time):
elapsed_time = time.time() - start_time
print(f"{label} took {elapsed_time:.2f} seconds.")

def reset_states(self):
# TODO: Implement a method to reset the state of the nowcast object to make multiple iterations possible
pass
def reset_states_and_params(self):
"""
Reset the internal state and parameters of the nowcaster to allow multiple forecasts.
This method resets the state and params to their initial conditions without reinitializing
the inputs like precip, velocity, time_steps, or config.
"""
# Re-initialize the state and parameters
self.state = StepsNowcasterState()
self.params = StepsNowcasterParams()

# Reset time measurement variables
self.start_time_init = None
self.init_time = None
self.mainloop_time = None


# Wrapper function to preserve backward compatibility
Expand Down Expand Up @@ -1256,6 +1267,6 @@ def forecast(
precip, velocity, timesteps, steps_config=nowcaster_config
)
forecast_steps_nowcast = nowcaster.compute_forecast()
nowcaster.reset_states()
nowcaster.reset_states_and_params()
# Call the appropriate methods within the class
return forecast_steps_nowcast

0 comments on commit 37739de

Please sign in to comment.