From 37739de53a14b4f21e340bf1624f0efc60d06ec7 Mon Sep 17 00:00:00 2001 From: Simon De Kock Date: Thu, 31 Oct 2024 19:29:24 +0100 Subject: [PATCH] Implemented a reset of the states and params to allow for multiple forecast runs in a row --- pysteps/nowcasts/steps.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pysteps/nowcasts/steps.py b/pysteps/nowcasts/steps.py index 78457c4c..a9ced155 100644 --- a/pysteps/nowcasts/steps.py +++ b/pysteps/nowcasts/steps.py @@ -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 @@ -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