1 from phase_plot_imports
import loader, np, sys
6 block_phase_data = True
8 parameters = loader.load_yaml_parameters(run_name)
10 start_index = threshold_dictionary[
'threshold_speed_start_index']
11 indexes =
make_indexes(start_index, threshold_dictionary, 100)
13 path_in_results_folder = run_name +
"/results/phase_plot_at_threshold_block.csv" 14 position = loader.load_simulation_output(parameters, run_name,
"block_position")
15 velocity = loader.load_simulation_output(parameters, run_name,
"block_velocity")
17 save_phase_data(phase_data,run_name, path_in_results_folder, block_phase_data=
True)
19 path_in_results_folder = run_name +
"/results/phase_plot_at_threshold_pad.csv" 20 position = loader.load_simulation_output(parameters, run_name,
"pad_position")
21 velocity = loader.load_simulation_output(parameters, run_name,
"pad_velocity")
29 path_in_results_folder = run_name +
"/results/phase_plot_at_threshold" + phase_part +
".csv" 30 if(loader.check_if_file_exist_in_run_folder(path_in_results_folder)
and pad_or_block(phase_part)):
31 print(
"Found phase plot at: ", path_in_results_folder)
33 parameters = loader.load_yaml_parameters(run_name)
35 if(
"_block" == phase_part):
36 position_selection = []
37 velocity_selection = []
38 for i
in range(0, int(len(phase_data)/2)):
39 position_selection.append(phase_data[2*i])
40 velocity_selection.append(phase_data[2*i+1])
42 position_selection = phase_data[0]
43 velocity_selection = phase_data[1]
44 return {
'position_selection': position_selection,
'velocity_selection': velocity_selection,
'parameters': parameters}
46 print(
"Sorry, the phase plot does not exist for this run.\n \ 47 Remove the \"-load\"-flag to produce it.")
53 threshold_speed = loader.get_parameter(parameters,
"threshold_speed")
54 speeds = loader.get_start_end_speed(parameters)
55 max_time = loader.get_parameter(parameters,
"max_time")
56 save_interval = loader.get_parameter(parameters,
"save_interval_dt")
57 dt = loader.get_parameter(parameters,
"dt")
58 steps_in_time_unit = 1 / (dt * save_interval)
59 n_steps = np.floor(max_time * steps_in_time_unit)
61 threshold_speed_start_index = int(np.ceil((threshold_speed - speeds[
'start_speed']) \
62 / (speeds[
'end_speed'] - speeds[
'start_speed']) \
64 return {
'threshold_speed': threshold_speed, \
65 'threshold_speed_start_index': threshold_speed_start_index, \
66 'start_speed': speeds[
'start_speed'], \
67 'end_speed': speeds[
'end_speed'], \
69 'steps_in_time_unit': steps_in_time_unit}
74 time_units_from_start = 1000
77 max_indexes_from_start = threshold_dictionary[
'n_steps'] - threshold_dictionary[
'threshold_speed_start_index']
78 if(start_index == max_indexes_from_start):
79 print(
"Can't have the start index be equal to the end index.")
82 print(start_index, end_index)
84 indexes = range(start_index,end_index)
92 indexes_from_start = np.floor(time_units_from_start * threshold_dictionary[
'steps_in_time_unit'])
93 max_indexes_from_start = threshold_dictionary[
'n_steps'] - threshold_dictionary[
'threshold_speed_start_index']
94 if(indexes_from_start > max_indexes_from_start):
95 print(
"Selected units greater than the size of the run. Using maximum amount of units.")
96 print(
"Selected: ", time_units_from_start)
97 print(
"Maximum: ", max_indexes_from_start / threshold_dictionary[
'steps_in_time_unit'])
98 indexes_from_start = max_indexes_from_start
99 return int(indexes_from_start)
107 if(check
in [
'block',
'both']):
108 path_in_results_folder = run_name +
"/results/phase_plot_at_threshold_block.csv" 109 if(
not loader.check_if_file_exist_in_run_folder(path_in_results_folder)):
113 if(check
in [
'pad',
'both']):
114 path_in_results_folder = run_name +
"/results/phase_plot_at_threshold_pad.csv" 115 if(
not loader.check_if_file_exist_in_run_folder(path_in_results_folder)):
119 if(found_block
and found_pad):
122 print(
"check-parameters must be one of [pad, block, both].")
131 path_in_results_folder,
132 block_phase_data = False
134 position_selection = phase_data[
'position']
135 velocity_selection = phase_data[
'velocity']
137 file_name =
"/results/phase_plot_at_threshold_" 138 if(loader.check_if_file_exist_in_run_folder(path_in_results_folder)
and not "-yes" in sys.argv):
141 if(block_phase_data
and len(position_selection) > 1):
143 for i
in range(0, len(position_selection)):
144 save_matrix.append(position_selection[i])
145 save_matrix.append(velocity_selection[i])
146 save_matrix = np.array(save_matrix)
147 file_name +=
"block.csv" 149 save_matrix = np.array([position_selection, velocity_selection])
150 file_name +=
"pad.csv" 151 loader.save_csv(run_name, file_name, save_matrix)
153 print(
"Skipped printing to file.")
158 response_from_user = input(output_to_user)
159 if(response_from_user ==
"yes"):
169 if(len(position.shape) == 1):
170 position_selection = position[indexes]
171 velocity_selection = velocity[indexes]
173 position_selection = position[:, indexes]
174 velocity_selection = velocity[:, indexes]
175 return {
'position': position_selection,
'velocity': velocity_selection}
180 return (phase_part
in [
"_pad",
"_block"])
188 "phase_plot_at_threshold" + phase_part, \
189 use_shared_names =
False \
198 parameters = loader.load_yaml_parameters(run_name)
199 phase_data = loader.load_simulation_output(\
203 use_shared_names = use_shared_names \
def make_indexes_within_interval(start_index, threshold_dictionary, time_units_from_start)
def make_indexes(start_index, threshold_dictionary, time_units_from_start=1000)
def lazy_load_data(run_name, file_name, use_shared_names)
def pad_or_block(phase_part)
def check_if_all_phase_data_exists(run_name, check="both")
def save_phase_data(phase_data, run_name, path_in_results_folder, block_phase_data=False)
def bool_interaction_with_user(output_to_user)
def get_threshold_speed(parameters)
def get_phase_selection(position, velocity, indexes)
def load_phase_data(run_name, phase_part="")
def create_phase_data(run_name, pad_phase_data=True, block_phase_data=True)
def load_phase_data_creator(run_name, phase_part="_block")