1 from phase_plot_imports
import *
3 from matplotlib.widgets
import Slider
10 threshold_speed = loader.get_parameter(parameters,
"threshold_speed")
11 speeds = loader.get_start_end_speed(parameters)
12 max_time = loader.get_parameter(parameters,
"max_time")
13 save_interval = loader.get_parameter(parameters,
"save_interval_dt")
14 dt = loader.get_parameter(parameters,
"dt")
15 steps_in_time_unit = 1 / (dt * save_interval)
16 n_steps = np.floor(max_time * steps_in_time_unit)
18 threshold_speed_start_index = int(np.ceil((threshold_speed - speeds[
'start_speed']) \
19 / (speeds[
'end_speed'] - speeds[
'start_speed']) \
21 return {
'threshold_speed': threshold_speed, \
22 'threshold_speed_start_index': threshold_speed_start_index, \
23 'start_speed': speeds[
'start_speed'], \
24 'end_speed': speeds[
'end_speed'], \
26 'steps_in_time_unit': steps_in_time_unit}
31 response_from_user = input(output_to_user)
32 if(response_from_user ==
"yes"):
41 file_name = "/results/phase_plot_at_threshold_"
44 if(loader.check_if_file_exist_in_run_folder(run_name, file_name)
and not "-yes" in sys.argv):
47 if(
"-block" in sys.argv
and len(position_selection) > 1):
49 for i
in range(0, len(position_selection)):
50 save_matrix.append(position_selection[i])
51 save_matrix.append(velocity_selection[i])
52 save_matrix = np.array(save_matrix)
53 file_name +=
"block.csv" 55 save_matrix = np.array([position_selection, velocity_selection])
56 file_name +=
"pad.csv" 57 loader.save_csv(run_name, file_name, save_matrix)
59 print(
"Skipped printing to file.")
66 indexes_from_start = np.floor(time_units_from_start * threshold_dictionary[
'steps_in_time_unit'])
67 max_indexes_from_start = threshold_dictionary[
'n_steps'] - threshold_dictionary[
'threshold_speed_start_index']
68 if(indexes_from_start > max_indexes_from_start):
69 print(
"Selected units greater than the size of the run. Using maximum amount of units.")
70 print(
"Selected: ", time_units_from_start)
71 print(
"Maximum: ", max_indexes_from_start / threshold_dictionary[
'steps_in_time_unit'])
72 indexes_from_start = max_indexes_from_start
73 return int(indexes_from_start)
78 time_units_from_start = 1000
81 max_indexes_from_start = threshold_dictionary[
'n_steps'] - threshold_dictionary[
'threshold_speed_start_index']
82 if(start_index == max_indexes_from_start):
83 print(
"Can't have the start index be equal to the end index.")
86 print(start_index, end_index)
88 indexes = range(start_index,end_index)
94 if(loader.check_if_file_exist_in_run_folder(run_name, \
95 "/results/phase_plot_at_threshold.csv")):
96 path_in_results_folder = run_name +
"/results/phase_plot_at_threshold.csv" 97 print(
"Found phase plot at: ", path_in_results_folder)
99 phase_data = loader.load_file(loader.results_path + \
100 path_in_results_folder)
101 if(
"-block" in sys.argv):
102 position_selection = []
103 velocity_selection = []
104 for i
in range(0, int(len(phase_data)/2)):
105 position_selection.append(phase_data[2*i])
106 velocity_selection.append(phase_data[2*i+1])
108 position_selection = phase_data[0]
109 velocity_selection = phase_data[1]
110 parameters = loader.load_yaml_parameters(run_name)
111 return {
'position_selection': position_selection,
'velocity_selection': velocity_selection,
'parameters': parameters}
113 print(
"Sorry, the phase plot does not exist for this run.\n \ 114 Remove the \"-load\"-flag to produce it.")
120 parameters = loader.load_yaml_parameters(run_name)
122 start_index = threshold_dictionary[
'threshold_speed_start_index']
123 indexes =
make_indexes(start_index, threshold_dictionary, 500)
124 if(
"-block" in sys.argv):
125 position = loader.load_simulation_output(parameters, run_name,
"block_position")
126 velocity = loader.load_simulation_output(parameters, run_name,
"block_velocity")
128 position = loader.load_simulation_output(parameters, run_name,
"pad_position")
129 velocity = loader.load_simulation_output(parameters, run_name,
"pad_velocity")
131 if(len(position.shape) == 1):
132 position_selection = position[indexes]
133 velocity_selection = velocity[indexes]
135 position_selection = position[:, indexes]
136 velocity_selection = velocity[:, indexes]
140 return {
'position_selection': position_selection,
'velocity_selection': velocity_selection,
'parameters': parameters}
149 custom_legend_title = ""
151 color_map = plt.cm.Set1
152 plt.figure(figure_number)
153 plot_a, = plt.plot(single_position, single_velocity, color = color_map(color_number), label =
"Phase plot" + custom_label)
154 plt.legend(title = custom_legend_title)
155 plt.xlabel(
"position")
156 plt.ylabel(
"velocity")
157 plt.figure(figure_number + 1)
158 plt.plot(single_position, color = color_map(color_number), label =
"Position plot" + custom_label)
159 plt.plot(single_velocity, color = color_map(color_number), linestyle =
"--", label =
"Velocity plot" + custom_label)
160 plt.legend(title = custom_legend_title)
161 plt.xlabel(
"position/velocity")
162 plt.ylabel(
"surface velocity")
170 custom_legend_title = "",
173 if(
"-block" in sys.argv):
176 max_position_amplitude = []
177 max_velocity_amplitude = []
178 for counter, (position, velocity)
in enumerate(zip(position, velocity)):
180 if(
"-bar" in sys.argv):
181 max_position_amplitude.append(np.max(position))
182 max_velocity_amplitude.append(np.max(velocity))
183 if(
"-bar" in sys.argv):
185 plt.bar(block_numbers, max_position_amplitude, align =
"edge", width = 0.5, label =
"Position")
186 plt.bar(block_numbers, max_velocity_amplitude, align =
"edge", width = -0.5, label =
"Velocity")
187 plt.legend(title =
"Max amplitues")
197 custom_legend_title = "",
200 n_elements = len(position)
201 n_sections = int(np.floor(n_elements/section_size))
202 rest = np.mod(n_elements, section_size)
203 for i
in range(0, n_sections):
204 start = i*section_size
205 end = (i+1)*section_size
206 section = range(start, end)
210 custom_label = custom_label,\
211 custom_legend_title=custom_legend_title,\
212 block_numbers = block_numbers[start:end])
214 section = range(-rest, 0)
219 custom_label = custom_label,\
220 custom_legend_title=custom_legend_title,\
221 block_numbers = block_numbers[-rest:])
228 custom_legend_title = "",
233 custom_label = custom_label +
". Block " + str(block_numbers[0]), \
234 custom_legend_title=custom_legend_title)
236 def update_section_frame(
239 frame_number = int(np.floor(slider_frame.val))
244 plot_a.set_ydata = velocity[frame_number]
247 frame = plt.axes([0.25, 0.1, 0.65, 0.03])
248 slider_frame = Slider(frame,
'Frame', 0, len(position), valinit = 0, valfmt=
'%d')
249 slider_frame.on_changed(update_section_frame)
def get_threshold_speed(parameters)
def make_indexes_within_interval(start_index, threshold_dictionary, time_units_from_start)
def create_and_get_phase_data(run_name)
def plot_phase_intervals(position, velocity, section_size, custom_label="", custom_legend_title="", block_numbers=None)
def plot_position_velocity(single_position, single_velocity, color_number, figure_number=1, custom_label="", custom_legend_title="")
def plot_one_phase_at_the_time(position, velocity, custom_label="", custom_legend_title="", block_numbers=None)
def get_saved_phase_data(run_name)
def save_phase_data(position_selection, velocity_selection, run_name, file_name="/results/phase_plot_at_threshold_")
def make_indexes(start_index, threshold_dictionary, time_units_from_start=1000)
def bool_interaction_with_user(output_to_user)
def plot_phase(position, velocity, figure_number, custom_label="", custom_legend_title="", block_numbers=None)