1 from run_animation_layout_support_functions
import *
9 shift_amount_per_frame = 1,
13 if(
"--friction" in sys.argv):
24 animation_plots = [position_plot, velocity_plot, phase_plot, bar_plot]
26 bk_animation =
BKAnimation(animation_plots, sleep_amount=0.001, max_lim_change=0.3)
27 bk_animation.init_live_plot((221, 222, 223, 224), (20,10), [
"Position",
"Velocity",
"Phase",
"Bar"])
28 bk_animation.update_subplots(update_lims=
False)
31 plot_shape = [len(animation_plots), len(position_plot.single_line_list)]
32 def plot_frames(n = 0):
37 bk_animation.change_y(3, 0)
39 bk_animation.check_lims(0,
"y")
40 bk_animation.check_lims(1,
"y")
41 bk_animation.check_lims(2,
"x")
42 bk_animation.check_lims(2,
"y")
44 bk_animation.update_subplots()
45 sleep(bk_animation.sleep_amount)
49 for i
in range(0, frames):
52 ani = animation.FuncAnimation(bk_animation.fig, plot_frames,500,interval=30)
53 writer = animation.writers[
'ffmpeg'](fps=20)
55 simulation_path = loader.get_simulation_path(run_name)
56 ani.save(simulation_path +
'/animation.mp4',writer=writer,dpi=100)
61 shift_amount_per_frame = 1,
65 sample_range = [0,2*100]
68 if(
not ppc.check_if_all_phase_data_exists(run_name)):
69 print(bcolors.WARNING +
"Making phase date since it did not exist." + bcolors.ENDC)
70 ppc.create_phase_data(run_name)
71 phase_data_block =
load_phase_data(run_name,
"_block")[sample_range[0]:sample_range[1]]
78 position_data_pad = phase_data_pad[0]
85 spring_plot =
make_single_line_spring_plot(position_plot, ax_number = 3, line_number = 0, pad_position = position_data_pad, common_indexes=shown_indexes)
86 animation_plots = [position_plot, bar_plot, phase_plot, spring_plot]
88 bk_animation =
BKAnimation(animation_plots, sleep_amount=0.001, max_lim_change=0.3)
89 bk_animation.init_live_plot((231, 232, 233, 212), (20,10), [
"Position",
"Bar",
"Phase",
"Spring"])
90 bk_animation.update_subplots(update_lims=
False)
93 plot_shape = [len(animation_plots), len(position_plot.single_line_list)]
94 def plot_frames(n = 0):
98 bk_animation.shift_x_indexes(ax_number = 3, line_number = 2, shift_amount = shift_amount_per_frame)
99 bk_animation.change_y(1, 0)
100 bk_animation.change_x(3, 0, get_axis=
"y")
101 bk_animation.change_x(3, 1)
102 bk_animation.update_upper_springs(3, index_first_spring = 3)
108 bk_animation.update_subplots()
109 sleep(bk_animation.sleep_amount)
113 for i
in range(0, frames):
116 ani = animation.FuncAnimation(bk_animation.fig, plot_frames, frames = frames,interval=30)
117 writer = animation.writers[
'ffmpeg'](fps=20)
119 simulation_path = loader.get_simulation_path(run_name)
120 ani.save(simulation_path +
'/animation_vid_7.mp4',writer=writer,dpi=100)
125 shift_amount_per_frame = 1,
127 live_plotting = True,
129 sample_range = [0,2*100]
132 if(
not ppc.check_if_all_phase_data_exists(run_name)):
133 print(bcolors.WARNING +
"Making phase date since it did not exist." + bcolors.ENDC)
134 ppc.create_phase_data(run_name)
135 phase_data_block =
load_phase_data(run_name,
"_block")[sample_range[0]:sample_range[1]]
141 print(phase_data_pad)
142 position_data_pad = phase_data_pad[0]
149 spring_plot =
make_single_line_spring_plot(position_plot, ax_number = 3, line_number = 0, pad_position = position_data_pad, common_indexes=shown_indexes)
150 animation_plots = [position_plot, bar_plot, position_pad_plot, spring_plot]
152 bk_animation =
BKAnimation(animation_plots, sleep_amount=0.001, max_lim_change=0.3)
153 bk_animation.init_live_plot((231, 232, 233, 212), (20,10), [
"Position",
"Bar",
"Position pad",
"Spring"])
154 bk_animation.update_subplots(update_lims=
False)
157 plot_shape = [len(animation_plots), len(position_plot.single_line_list)]
158 def plot_frames(n = 0):
162 bk_animation.shift_x_indexes(ax_number = 3, line_number = 2, shift_amount = shift_amount_per_frame)
163 bk_animation.change_y(1, 0)
164 bk_animation.change_x(3, 0, get_axis=
"y")
165 bk_animation.change_x(3, 1)
166 bk_animation.update_upper_springs(3, index_first_spring = 3)
167 bk_animation.update_subplots()
168 sleep(bk_animation.sleep_amount)
172 for i
in range(0, frames):
175 ani = animation.FuncAnimation(bk_animation.fig, plot_frames, frames = frames,interval=30)
176 writer = animation.writers[
'ffmpeg'](fps=20)
178 simulation_path = loader.get_simulation_path(run_name)
179 ani.save(simulation_path +
'/animation_vid_bk.mp4',writer=writer,dpi=100)
184 shift_amount_per_frame = 1,
186 live_plotting = True,
187 sample_range = [0,2*100],
191 frames_per_velocity = phase_data_block.shape[1]
192 velocities =
loadYaml(run_name,
"/results/friction_phase/increment_run.yaml")[
"velocities"]
193 for i
in range(velocity_index + 1, len(velocities)):
194 phase_data_block = np.concatenate((phase_data_block,
load_friction_phase_data(run_name,
"block_phase_" + str(i))), axis=1)
197 number_of_data_points = len(position_data[0])
198 if(frames > number_of_data_points):
199 frames = number_of_data_points
205 animation_plots = [position_plot, bar_plot, phase_plot, spring_plot]
207 bk_animation =
BKAnimation(animation_plots, sleep_amount=0.000, max_lim_change=0.3)
208 bk_animation.init_live_plot((231, 232, 233, 212), (20,10), [
"Position",
"Bar",
"Phase",
"Spring"], show_plot = live_plotting, suptitle=
"Velocity: " + str(velocities[velocity_index]))
211 plot_shape = [len(animation_plots), len(position_plot.single_line_list)]
212 only_shift_first =
False 213 only_shift_first_index = number_of_data_points - shown_indexes[1] - 1
214 def init_plot_frames():
215 bk_animation.update_subplots(update_lims=
False)
217 nonlocal velocity_index, only_shift_first
218 bk_animation.update_suptitle(
"Velocity: %(velocity)1.3f | Frame: %(frame)i" % {
'velocity': velocities[velocity_index],
'frame': n})
219 if(n % frames_per_velocity == 0
and n > 0):
222 if(n % only_shift_first_index == 0
and n > 0):
223 only_shift_first =
True 224 shift_z_indexes_of_lines_in_ax(bk_animation, shift_amount_per_frame, ax_number = 0, n_line_number = plot_shape[1], index_type =
'y', only_shift_first = only_shift_first)
225 shift_z_indexes_of_lines_in_ax(bk_animation, shift_amount_per_frame, ax_number = 2, n_line_number = plot_shape[1], index_type =
'xy', only_shift_first = only_shift_first)
227 bk_animation.change_y(1, 0)
228 bk_animation.change_x(3, 0, get_axis=
"y")
230 bk_animation.update_upper_springs(3, index_first_spring = 1)
232 bk_animation.update_subplots()
233 sleep(bk_animation.sleep_amount)
238 for i
in range(0, frames):
241 ani = animation.FuncAnimation(bk_animation.fig, plot_frames, init_func = init_plot_frames, frames = frames,interval=30)
242 writer = animation.writers[
'ffmpeg'](fps=20)
244 simulation_path = loader.get_simulation_path(run_name)
245 ani.save(simulation_path +
'/animation_vid_7.mp4',writer=writer,dpi=100)
250 shift_amount_per_frame = 1,
252 live_plotting = True,
253 sample_range = [0,2*100],
258 frames_per_velocity = phase_data_block.shape[1]
259 velocities =
loadYaml(run_name,
"/results/friction_phase/increment_run.yaml")[
"velocities"]
260 for i
in range(velocity_index + 1, len(velocities)):
261 phase_data_block = np.concatenate((phase_data_block,
load_friction_phase_data(run_name,
"block_phase_" + str(i))), axis=1)
262 phase_data_pad = np.concatenate((phase_data_pad,
load_friction_phase_data(run_name,
"pad_phase_" + str(i))), axis=1)
265 if(
"--nopad" in sys.argv):
266 phase_shape_block = phase_data_block.shape
267 block_average = np.zeros(phase_shape_block[1])
268 number_of_blocks = int(phase_shape_block[0]/2)
269 for i
in range(0, number_of_blocks):
270 block_average += phase_data_block[2*i]
271 position_data_pad = block_average/number_of_blocks
273 position_data_pad_title =
"Block avg. position" 274 position_data_pad_y_label =
"$\\frac{\sum_1^n u_i}{n}$" 276 index_first_spring = 1
278 position_data_pad = phase_data_pad[0]
279 position_data_pad_title =
"Pad position" 280 position_data_pad_y_label =
"$x$" 282 index_first_spring = 3
285 number_of_data_points = len(position_data[0])
286 if(frames > number_of_data_points):
287 frames = number_of_data_points
289 position_plot =
make_single_line_line_plot(position_data, shown_indexes, ax_number = 0, y_min = -3.0, y_max = 2.0, x_label=
"Time steps shown", y_label=
"$u_i$")
291 position_pad_plot =
make_single_line_line_plot([position_data_pad], shown_indexes, ax_number = 2, y_min = -3.0, y_max = 2.0, x_label=
"Time steps shown", y_label=position_data_pad_y_label)
292 spring_plot =
make_single_line_spring_plot(position_plot, ax_number = 3, line_number = 0, common_indexes=shown_indexes, pad_position=position_data_pad, x_label=
"$x$", y_label=
"Model", show_pad = show_pad)
293 animation_plots = [position_plot, bar_plot, position_pad_plot, spring_plot]
295 bk_animation =
BKAnimation(animation_plots, sleep_amount=0.000, max_lim_change=0.3)
296 bk_animation.init_live_plot((231, 232, 233, 212), (20,10), [
"Position",
"Bar", position_data_pad_title,
"Spring"], show_plot = live_plotting, suptitle=
"Velocity: " + str(velocities[velocity_index]))
299 plot_shape = [len(animation_plots), len(position_plot.single_line_list)]
300 only_shift_first =
False 301 only_shift_first_index = number_of_data_points - shown_indexes[1] - 1
302 def init_plot_frames():
303 bk_animation.update_subplots(update_lims=
False)
305 nonlocal velocity_index, only_shift_first
306 bk_animation.update_suptitle(
"Velocity: %(velocity)1.3f | Frame: %(frame)i" % {
'velocity': velocities[velocity_index],
'frame': n})
307 if(n % frames_per_velocity == 0
and n > 0):
310 if(n % only_shift_first_index == 0
and n > 0):
311 only_shift_first =
True 312 shift_z_indexes_of_lines_in_ax(bk_animation, shift_amount_per_frame, ax_number = 0, n_line_number = plot_shape[1], index_type =
'y', only_shift_first = only_shift_first)
313 shift_z_indexes_of_lines_in_ax(bk_animation, shift_amount_per_frame, ax_number = 2, n_line_number = 1, index_type =
'y', only_shift_first = only_shift_first)
315 bk_animation.change_y(1, 0)
316 bk_animation.change_x(3, 0, get_axis=
"y")
318 bk_animation.change_x(3, 1)
319 bk_animation.update_upper_springs(3, index_first_spring = index_first_spring)
321 bk_animation.update_subplots()
322 sleep(bk_animation.sleep_amount)
327 for i
in range(0, frames):
332 ani = animation.FuncAnimation(bk_animation.fig, plot_frames, init_func = init_plot_frames, frames = frames,interval=30)
333 writer = animation.writers[
'ffmpeg'](fps=20)
335 simulation_path = loader.get_simulation_path(run_name)
336 ani.save(simulation_path +
'/animation_vid_7.mp4',writer=writer,dpi=100)
338 if __name__ ==
"__main__":
339 shown_indexes = [0, 100]
340 if(len(sys.argv) >= 2):
341 live_plotting =
False 343 if(
'-l' in sys.argv):
345 if(
'-d' in sys.argv):
348 if(
'--friction' in sys.argv):
352 pos_pos_spr(sys.argv[1], shown_indexes, live_plotting=live_plotting, sample_mode=sample_mode)
def pos_pha_spr_friction(run_name, shown_indexes, shift_amount_per_frame=1, frames=3699, live_plotting=True, sample_range=[0, velocity_index=8)
def make_single_line_spring_plot(single_plot, ax_number, line_number, pad_position=[], common_indexes=[], height_of_plot=0.1, x_label="", y_label="", show_pad=False)
def make_single_line_bar_plot(single_plot, ax_number, line_number, x_label="", y_label="")
def load_phase_data(run_name, phase_part="")
def pos_vel_pha_bar(run_name, shown_indexes, shift_amount_per_frame=1, frames=500, live_plotting=True)
def seperate_pos_vel_data(phase_data)
def pos_pos_spr(run_name, shown_indexes, shift_amount_per_frame=1, frames=500, live_plotting=True, sample_mode=False, sample_range=[0)
def pos_pos_spr_friction(run_name, shown_indexes, shift_amount_per_frame=1, frames=3699, live_plotting=True, sample_range=[0, velocity_index=14)
def make_single_line_phase_plot(y_data, x_data, common_indexes, ax_number, x_label="", y_label="")
def make_single_line_line_plot(y_data, common_indexes, ax_number, x_values=[], y_min=0, y_max=0, x_label="", y_label="")
def pos_pha_spr(run_name, shown_indexes, shift_amount_per_frame=1, frames=500, live_plotting=True, sample_mode=False, sample_range=[0)
def load_friction_phase_data(run_name, phase_part="")
def shift_z_indexes_of_lines_in_ax(bk_animation, shift_amount_per_frame, ax_number, n_line_number, index_type, only_shift_first=False)