My Project
run_animation_layout_support_functions.py
Go to the documentation of this file.
1 from animation_run_imports import *
2 
4  run_name,
5  phase_part = ""
6 ):
7  phase_data = lazy_load_data(\
8  run_name, \
9  "phase_plot_at_threshold" + phase_part, \
10  use_shared_names = False \
11  )
12  return phase_data
13 
15  run_name,
16  phase_part = ""
17 ):
18  phase_data = lazy_load_data(\
19  run_name, \
20  "/friction_phase/" + phase_part, \
21  use_shared_names = False \
22  )
23  return phase_data
24 
25 def lazy_load_data(
26  run_name,
27  file_name,
28  use_shared_names
29 ):
30  parameters = loader.load_yaml_parameters(run_name)
31  phase_data = loader.load_simulation_output(\
32  parameters,\
33  run_name, \
34  file_name, \
35  use_shared_names = use_shared_names \
36  )
37  return phase_data
38 
39 def loadYaml(
40  run_name,
41  file_name
42 ):
43  yaml = loader.loadYaml(run_name, file_name)
44  return yaml
45 
47  y_data,
48  common_indexes,
49  ax_number,
50  x_values = [],
51  y_min = 0,
52  y_max = 0,
53  x_label = "",
54  y_label = ""
55 ):
56  if(y_min == y_max == 0):
57  y_lim = {\
58  'min': np.min(y_data), \
59  'max': np.max(y_data)\
60  }
61  else:
62  y_lim = {\
63  'min': y_min, \
64  'max': y_max\
65  }
66  x_lim = {'min': common_indexes[0], 'max': common_indexes[1] - 1}
67 
68  line_list = []
69  for i, y_values in enumerate(y_data):
70  if(len(x_values) == 0):
71  x_values = np.arange(len(y_values))
72  single_line = SingleLine(\
73  x_values, \
74  y_values, \
75  x_indexes = common_indexes, \
76  y_indexes = common_indexes, \
77  ax_number = ax_number, \
78  line_number = i)
79 
80  line_list.append(single_line)
81 
82  single_plot = SinglePlot(\
83  ax_number, \
84  y_lim = y_lim, \
85  x_lim = x_lim, \
86  single_line_list = line_list, \
87  plot_type = "line",
88  x_label = x_label,
89  y_label = y_label)
90 
91  return single_plot
92 
94  y_data,
95  x_data,
96  common_indexes,
97  ax_number,
98  x_label = "",
99  y_label = ""
100 ):
101  y_lim = {\
102  'min': np.min(y_data), \
103  'max': np.max(y_data)\
104  }
105  x_lim = {\
106  'min': np.min(x_data), \
107  'max': np.max(x_data)\
108  }
109 
110  line_list = []
111  for i, (y_values, x_values) in enumerate(zip(y_data, x_data)):
112  single_line = SingleLine(\
113  x_values, \
114  y_values, \
115  x_indexes = common_indexes, \
116  y_indexes = common_indexes, \
117  ax_number = ax_number, \
118  line_number = i)
119 
120  line_list.append(single_line)
121 
122  single_plot = SinglePlot(\
123  ax_number, \
124  y_lim = y_lim, \
125  x_lim = x_lim, \
126  single_line_list = line_list, \
127  plot_type = "line",
128  x_label = x_label,
129  y_label = y_label)
130 
131  return single_plot
132 
134  single_plot,
135  ax_number,
136  line_number,
137  x_label = "",
138  y_label = ""
139 ):
140  n_bar_values = len(single_plot.single_line_list)
141  bar_values = np.array([single_plot.get_last_plotted_y_value(i) for i in range(0, n_bar_values)])
142  bar_position = np.array(np.arange(0, n_bar_values))
143  bar_lim = {'min': -0.5, 'max': n_bar_values - 0.5}
144  y_lim = single_plot.y_lim
145  if(y_lim['min'] > 0.0):
146  y_lim['min'] = 0.0
147  elif(y_lim['max'] < 0.0):
148  y_lim['max'] = 0.0
149  line_dependencies = {'ax_numbers': [single_plot.ax_number], 'line_numbers': [bar_position]}
150  bar_line = SingleLine(bar_position, bar_values, x_indexes=bar_position, y_indexes=bar_position, ax_number = ax_number, line_number = line_number, line_dependencies=line_dependencies)
151  bar_plot = SinglePlot(
152  ax_number,
153  single_line_list = [bar_line],
154  x_lim=bar_lim,
155  y_lim=y_lim,
156  plot_type = 'bar',
157  x_label = x_label,
158  y_label = y_label)
159 
160  return bar_plot
161 
163  single_plot,
164  ax_number,
165  line_number,
166  pad_position = [],
167  common_indexes = [],
168  height_of_plot = 0.1,
169  x_label = "",
170  y_label = "",
171  show_pad = False
172 ):
173  n_spring_values = len(single_plot.single_line_list)
174  spring_values = np.array([single_plot.get_last_plotted_y_value(i) for i in range(0, n_spring_values)])
175  spring_positions = np.array(np.arange(0, n_spring_values))
176  spring_lim = {'min': -height_of_plot/2, 'max': height_of_plot}
177  line_dependencies = {'ax_numbers': [single_plot.ax_number], 'line_numbers': [spring_positions]}
178  spring_indexes = [spring_positions[0], spring_positions[-1]]
179 
180  spring_line = SingleLine(x_values = spring_values, \
181  y_values = np.array([0.0]*n_spring_values), \
182  starting_position = {"x":spring_positions, "y": 0.0}, \
183  x_indexes=spring_indexes, \
184  y_indexes=spring_indexes, \
185  ax_number = ax_number, \
186  line_number = line_number, \
187  line_dependencies=line_dependencies,
188  marker="s",
189  marker_size=5.0)
190 
191  line_shifter = 1
192  line_list = [spring_line]
193 
194  if(len(pad_position) > 0 and len(common_indexes) > 0 and show_pad):
195  pad_line = SingleLine(x_values = np.array([pad_position[common_indexes[-1]]]*2), \
196  y_values = np.array([height_of_plot/2]*2), \
197  starting_position = {"x":np.array(spring_positions[[0,-1]]), "y": 0.0}, \
198  x_indexes = np.array([0, 1]), \
199  y_indexes = np.array([0, 1]), \
200  ax_number = ax_number, \
201  line_number = line_number + 1, \
202  line_dependencies= {'ax_numbers': [ax_number], 'line_numbers': [np.array([line_number + 2]*2)]}, \
203  line_width= 10.0,
204  color = 'tab:grey')
205  pad_values = SingleLine(x_values = np.array(pad_position), \
206  y_values = np.array([height_of_plot/2]),
207  x_indexes = [common_indexes[-1]]*2,
208  y_indexes = [0]*2,
209  ax_number = ax_number,
210  line_number = line_number + 2,
211  marker = '+'
212  )
213  line_shifter += 2
214  line_list += [pad_line, pad_values]
215 
216 
217 
218  for i, (spring_value, spring_position) in enumerate(zip(spring_values, spring_positions)):
219  x_values = np.array([spring_position + spring_value, spring_position])
220  y_values = np.array([0, height_of_plot/2])
221  common_indexes = np.array([0,1])
222  single_line = SingleLine(\
223  x_values, \
224  y_values, \
225  x_indexes = common_indexes, \
226  y_indexes = common_indexes, \
227  ax_number = ax_number, \
228  line_number = i + line_shifter,
229  color = 'tab:red')
230  line_list.append(single_line)
231 
232  spring_plot = SinglePlot(ax_number, \
233  single_line_list = line_list, \
234  x_lim={'min': -3.0 + spring_positions[0], \
235  'max': 3.0 + spring_positions[-1]}, \
236  y_lim=spring_lim, \
237  plot_type = 'spring',
238  x_label = x_label,
239  y_label = y_label)
240 
241  return spring_plot
242 
243 
245  phase_data
246 ):
247  pos_data = []
248  vel_data = []
249 
250  for i in range(0, int(len(phase_data)/2)):
251  pos_data.append(phase_data[2*i])
252  vel_data.append(phase_data[2*i + 1])
253 
254  return (pos_data, vel_data)
255 
257  bk_animation,
258  shift_amount_per_frame,
259  ax_number,
260  n_line_number,
261  index_type,
262  only_shift_first = False
263 ):
264  for line_number in range(0, n_line_number):
265  if(index_type == 'y'):
266  bk_animation.shift_y_indexes(ax_number, line_number, shift_amount_per_frame, only_shift_first = only_shift_first)
267  if(only_shift_first):
268  bk_animation.shift_x_indexes(ax_number, line_number, shift_amount_per_frame, only_shift_first = only_shift_first)
269  elif(index_type == 'xy'):
270  bk_animation.shift_xy_indexes(ax_number, line_number, shift_amount_per_frame, only_shift_first = only_shift_first)
271  elif(index_type == 'x'):
272  bk_animation.shift_x_indexes(ax_number, line_number, shift_amount_per_frame, only_shift_first = only_shift_first)
273  else:
274  print("unknown access type")
275 
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 make_single_line_phase_plot(y_data, x_data, common_indexes, ax_number, x_label="", y_label="")
def lazy_load_data(run_name, file_name, use_shared_names)
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 shift_z_indexes_of_lines_in_ax(bk_animation, shift_amount_per_frame, ax_number, n_line_number, index_type, only_shift_first=False)