Skip to content

Commit

Permalink
MNT: minor improvements and refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusStano committed Feb 7, 2024
1 parent 003c1dc commit b012ca1
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions rocketpy/simulation/dispersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,6 @@ class Dispersion:
plot : _DispersionPlots
Object with methods to plot information about the dispersion
simulation.
_inputs_dict : dict
Dictionary with the inputs of the last simulation.
_last_print_len : int
Used to print on the same line.
_input_file : str
String containing the filepath of the input file
_output_file : str
String containing the filepath of the output file
_error_file : str
String containing the filepath of the error file
_number_of_simulations : int
Number of simulations to be run, must be non-negative.
_iteration_count : int
Number of simulations already run.
_start_time : float
Time when the simulation started.
_start_cpu_time : float
CPU time when the simulation started.
_input_file : str
String containing the filepath of the input file
_output_file : str
String containing the filepath of the output file
_error_file : str
String containing the filepath of the error file
"""

def __init__(self, filename, environment, rocket, flight, export_list=None):
Expand Down Expand Up @@ -238,10 +214,14 @@ def __run_single_simulation(self, input_file, output_file):
output_file=output_file,
)

average_time = (process_time() - self.start_cpu_time) / self.iteration_count
estimated_time = int(
(self.number_of_simulations - self.iteration_count) * average_time
)
self.__reprint(
f"Current iteration: {self.iteration_count:06d} | "
f"Average Time per Iteration: {((process_time() - self.start_cpu_time) / self.iteration_count):2.6f} s | "
f"Estimated time left: {int((self.number_of_simulations - self.iteration_count) * ((process_time() - self.start_cpu_time) / self.iteration_count))} s",
f"Average Time per Iteration: {average_time:.3f} s | "
f"Estimated time left: {estimated_time} s",
end="\r",
flush=True,
)
Expand All @@ -260,7 +240,7 @@ def __finalize_simulation(self, input_file, output_file, error_file):
f"{time() - self.start_time:.1f} s\n"
)

self.__reprint(final_string + f"Saving results.", flush=True)
self.__reprint(final_string + "Saving results.", flush=True)

# close files to guarantee saving
self.__close_files(input_file, output_file, error_file)
Expand Down Expand Up @@ -534,9 +514,9 @@ def set_processed_results(self):
"""Creates a dictionary with the mean and standard deviation of each
parameter available in the results"""
self.processed_results = {}
for result in self.results.keys():
mean = np.mean(self.results[result])
stdev = np.std(self.results[result])
for result, values in self.results.items():
mean = np.mean(values)
stdev = np.std(values)
self.processed_results[result] = (mean, stdev)

def import_outputs(self, filename=None):
Expand Down Expand Up @@ -653,7 +633,7 @@ def import_results(self, filename=None):
self.import_inputs(filename=filepath)
self.import_errors(filename=filepath)

def exportEllipsesToKML(
def export_ellipses_to_kml(
self,
filename,
origin_lat,
Expand Down Expand Up @@ -748,7 +728,7 @@ def info(self):
"""Print information about the monte carlo simulation."""
self.prints.all_results()

def allInfo(self):
def all_info(self):
"""Print and plot information about the monte carlo simulation
and its results.
Expand Down

0 comments on commit b012ca1

Please sign in to comment.