1 from animation_run_imports
import *
9 return a * np.sin(np.pi * f * x + p)
16 common_indexes = [0, 100]
17 ax_numbers = [0, 1, 2, 3]
18 shift_amount_per_frame = 3
24 y_lim = {
'min': -amplitude,
'max': amplitude}
25 x_lim = {
'min': common_indexes[0],
'max': common_indexes[1]}
27 single_line_1 =
SingleLine(x, sin_line_1, starting_position={
"x":0.5,
"y": 0.0}, x_indexes = common_indexes, y_indexes = common_indexes, ax_number = ax_numbers[0], line_number = 0, marker =
"x", marker_size=5.0)
28 single_line_2 =
SingleLine(x, sin_line_2, starting_position={
"x":0.0,
"y": 0.0}, x_indexes = common_indexes, y_indexes = common_indexes, ax_number = ax_numbers[0], line_number = 1, marker =
"^", marker_size=5.0)
29 single_line_3 =
SingleLine(sin_line_1, sin_line_2, x_indexes = common_indexes, y_indexes = common_indexes, ax_number = ax_numbers[1], line_number = 0)
31 single_plot_1 =
SinglePlot(ax_numbers[0], y_lim=y_lim, x_lim=x_lim, single_line_list=[single_line_1, single_line_2])
34 single_plot_2 =
SinglePlot(ax_numbers[1], y_lim=y_lim, x_lim=y_lim)
35 single_plot_2.append_single_line(single_line_3)
38 bar_values = np.array([single_plot_1.get_last_plotted_y_value(0), single_plot_1.get_last_plotted_y_value(1)])
39 bar_position = np.array([0, 1])
40 bar_lim = {
'min': -0.5,
'max': 1.5}
41 line_dependencies = {
'ax_numbers': [0],
'line_numbers': [[0,1]]}
42 single_line_bar =
SingleLine(bar_position, bar_values, x_indexes=bar_position, y_indexes=bar_position, ax_number = ax_numbers[2], line_number = 0, line_dependencies=line_dependencies)
43 single_plot_3 =
SinglePlot(ax_numbers[2], y_lim=y_lim, x_lim=bar_lim, single_line_list=[single_line_bar], plot_type =
'bar')
47 starting_position={
"x":np.array([0.1, 0.0]),
"y": 0.0}, \
48 x_indexes=bar_position, \
49 y_indexes=bar_position, \
50 ax_number = ax_numbers[3],
52 line_dependencies=line_dependencies, \
53 marker =
"s", marker_size = 10.0)
57 single_line_list=[single_line_spring], \
60 bk_animation =
BKAnimation([single_plot_1, single_plot_2, single_plot_3, single_plot_4])
62 single_line_bar.print_all()
64 bk_animation.init_live_plot((223, 221, 222, 224), (20,20), [
"Position",
"Phase",
"Velocity",
"Spring"])
66 for i
in range(0, 500):
67 bk_animation.shift_y_indexes(ax_numbers[0], 0, shift_amount_per_frame)
68 bk_animation.shift_y_indexes(ax_numbers[0], 1, shift_amount_per_frame)
69 bk_animation.shift_xy_indexes(ax_numbers[1], 0, shift_amount_per_frame)
70 bk_animation.change_y(ax_numbers[2], 0)
71 bk_animation.change_x(ax_numbers[3], 0, get_axis=
"y")
73 bk_animation.update_subplots()
75 print(
"NEW FRAME \n\n")
83 line_dependencies = None
85 if(len(x_values) == 0):
86 x_values = np.arange(len(y_values))
87 single_line =
SingleLine(x_values, y_values, x_indexes = common_indexes, y_indexes = common_indexes, ax_number = ax_number, line_number = line_number, line_dependencies=line_dependencies)
98 single_plot =
SinglePlot(ax_number, y_lim=y_lim, x_lim=x_lim, single_line_list=single_lines, plot_type=plot_type)
101 def plot_blocks(run_name, number_of_blocks = 2, common_indexes = [0, 20], frames = 500, live_plotting = True):
102 parameters = loader.load_yaml_parameters(run_name)
103 phase_data = loader.load_simulation_output(parameters, run_name,
"phase_plot_at_threshold", use_shared_names =
False)
104 print(phase_data.shape)
107 y_lim_position = {
'min': np.min(phase_data[number_of_blocks * 2]),
'max': np.max(phase_data[number_of_blocks * 2])}
108 y_lim_velocity = {
'min': np.min(phase_data[number_of_blocks * 2 +1]),
'max': np.max(phase_data[number_of_blocks * 2+1])}
110 x_lim = {
'min': common_indexes[0],
'max': common_indexes[1]}
111 shift_amount_per_frame = 1
115 for i
in range(0, number_of_blocks):
121 phase_line =
make_block_single_line(position_lines[0].y_values, 1, 0, common_indexes, x_values=velocity_lines[0].y_values)
122 phase_line_2 =
make_block_single_line(position_lines[1].y_values, 1, 1, common_indexes, x_values=velocity_lines[1].y_values)
125 bar_values = np.array([position_plot.get_last_plotted_y_value(0), position_plot.get_last_plotted_y_value(1)])
126 bar_position = np.array([0, 1,])
127 bar_lim = {
'min': -0.5,
'max': 1.5}
128 line_dependencies = {
'ax_numbers': [0],
'line_numbers': [[0,1]]}
129 bar_line =
make_block_single_line(bar_values, 2, 0, bar_position, x_values=bar_position, line_dependencies=line_dependencies)
132 bk_animation =
BKAnimation([position_plot, phase_plot, bar_plot, velocity_plot], sleep_amount=0.01, max_lim_change=0.5)
133 bk_animation.init_live_plot((221, 222, 224, 223), (20,10), [
"Position",
"Phase",
"Position bar",
"Velocity"])
134 print(bk_animation.get_last_plotted_y_value(2, 0))
136 bk_animation.update_subplots(update_lims=
True)
137 bk_animation.check_lims(1,
'x')
138 def plot_frames(n = 0):
139 bk_animation.check_lims(1,
"x")
140 bk_animation.check_lims(1,
"y")
141 bk_animation.shift_y_indexes(0, 0, shift_amount_per_frame)
142 bk_animation.shift_y_indexes(0, 1, shift_amount_per_frame)
143 bk_animation.shift_y_indexes(3, 0, shift_amount_per_frame)
144 bk_animation.shift_y_indexes(3, 1, shift_amount_per_frame)
145 bk_animation.shift_xy_indexes(1, 0, shift_amount_per_frame)
146 bk_animation.shift_xy_indexes(1, 1, shift_amount_per_frame)
147 print(bk_animation.get_last_plotted_y_value(2, 0))
148 bk_animation.change_y(2, 0)
149 bk_animation.update_subplots()
150 sleep(bk_animation.sleep_amount)
153 for i
in range(0, frames):
156 ani = animation.FuncAnimation(bk_animation.fig, plot_frames,300,interval=30)
157 writer = animation.writers[
'ffmpeg'](fps=30)
159 ani.save(
'demo.mp4',writer=writer,dpi=100)
161 if __name__ ==
"__main__":
162 if(
'-demo' in sys.argv):
164 elif(len(sys.argv) == 2):
def create_sine_wave(x, a, f, p)
def plot_blocks(run_name, number_of_blocks=2, common_indexes=[0, frames=500, live_plotting=True)
def make_block_single_line(y_values, ax_number, line_number, common_indexes, x_values=[], line_dependencies=None)
def make_block_single_plot(single_lines, ax_number, x_lim, y_lim, plot_type='line')