Skip to content

Commit

Permalink
only call the callback when we would output data
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Aug 30, 2024
1 parent 540885a commit 8f1da69
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ def solve(self, output_path=None, callback=None):
output_array.append(row)
next_output_time += self.box_model_options.output_step_time

# calls callback function if present
if callback is not None:
df = pd.DataFrame(output_array[:-1], columns=output_array[0])
callback(df, curr_time, curr_conditions, self.box_model_options.simulation_length)

# ensure the time step is not greater than the next update to the
# evolving conditions or the next output time
time_step = self.box_model_options.chem_step_time
Expand All @@ -561,12 +566,6 @@ def solve(self, output_path=None, callback=None):

# increments time
curr_time += time_step

# calls callback function if present
if callback is not None:
df = pd.DataFrame(output_array[:-1], columns=output_array[0])
callback(df, curr_time, curr_conditions, self.box_model_options.simulation_length)

df = pd.DataFrame(output_array[1:], columns=output_array[0])
# outputs to file if output is present
if output_path is not None:
Expand Down

0 comments on commit 8f1da69

Please sign in to comment.