My Project
plotBlocks.py
Go to the documentation of this file.
1 from analysisSharedFunctions import loadYaml, loadFile, \
2  loadPhaseFile, fourierSpectrum
3 from plotSetUp import setSvgLatexMatplotlibSettings, \
4  colors_qualitative_short as colors_short, \
5  colors_qualitative_long as colors_long, \
6  linestyles, \
7  checkIfMultipleBlocks, \
8  createTimeStepValues
9 import sys
10 from matplotlib import pyplot as plt
11 
12 
14 
15 
17  time_steps,
18  block_data,
19  yaml_file,
20  legend_title="",
21  legend_loc="lower right",
22  y_label="",
23  x_label="\$t\$"
24 ):
25  multiple_blocks = checkIfMultipleBlocks(block_data)
26  print(multiple_blocks)
27  print(block_data.shape)
28  if(multiple_blocks):
29  for i, block in enumerate(block_data):
30  plt.plot(time_steps, block,
31  color=colors_short[i % len(colors_short)],
32  linestyle=linestyles[i % len(linestyles)],
33  label="Block: " + str(i)
34  )
35  else:
36  plt.plot(time_steps, block_data,
37  color=colors_short[0 % len(colors_short)],
38  linestyle=linestyles[0 % len(linestyles)],
39  label="Block: " + str(0)
40  )
41  plt.legend(title=legend_title, loc=legend_loc)
42  plt.ylabel(y_label)
43  plt.xlabel(x_label)
44  plt.show()
45 
46 
47 def prettyPlotPhase(
48  phase_data,
49  y_label="\$x\$",
50  x_label="\$\\dot{x}\$",
51  alpha=1.0,
52  color_index=0,
53  line_style_index=0,
54  label=""
55 ):
56  plt.plot(phase_data[1], phase_data[0],
57  color=colors_long[color_index],
58  linestyle=linestyles[line_style_index],
59  label=label,
60  linewidth=0.7,
61  alpha=alpha
62  )
63  plt.ylabel(y_label)
64  plt.xlabel(x_label)
65 
66 
68  fourier_dictionary,
69  y_label="\$A\$",
70  x_label="\$f\$",
71  alpha=1.0,
72  color_index=0,
73  line_style_index=0,
74  label=""
75 ):
76 
77  plt.plot(fourier_dictionary["x_values"][1:],
78  fourier_dictionary["y_values"][1:],
79  color=colors_long[color_index],
80  linestyle=linestyles[line_style_index],
81  label=label)
82  #plt.xlim(0.0, 2.0)
83  plt.ylabel(y_label)
84  plt.xlabel(x_label)
85 
86 
87 def plot_blocks(
88  run_name
89 ):
90  yaml_file = loadYaml(run_name)
91  block_positions = loadFile(run_name, yaml_file,
92  file_name="block_position")
93  block_velocities = loadFile(run_name, yaml_file,
94  file_name="block_velocity")
95  time_steps = createTimeStepValues(block_positions, yaml_file)
96 
97  prettyPlotBlocks(time_steps, block_positions, yaml_file,
98  y_label="\$u_j\$")
99  prettyPlotBlocks(time_steps, block_velocities, yaml_file,
100  y_label="\$\dot{u_j}\$")
101  plt.show()
102 
103 
104 def plot_phase(
105  run_name
106 ):
107  yaml_file = loadYaml(run_name)
108  increment = yaml_file["Parameters"]["increment"]
109  blocks = yaml_file["Parameters"]["blocks"]
110  print(blocks)
111  slider_velocities = [8, 11, 67, 72, 111, 130]
112  phase_labels = [str(round(abs(increment*velocity),2)) for velocity in slider_velocities]
113  if(increment < 0):
114  slider_velocities = [int(149 - slider_velocity) for slider_velocity in slider_velocities]
115  plt.figure()
116  for i, velocity in enumerate(slider_velocities):
117  phase_data = loadPhaseFile(run_name, "block_phase_" + str(velocity))
118 
119  for j in range(0,len(phase_data)//2):
120  # time_steps = createTimeStepValues(phase_data[0], yaml_file)
121  # prettyPlotBlocks(time_steps, phase_data[j*2], yaml_file,
122  # y_label="\$u_j\$")
123  plt.subplot(121)
124  prettyPlotPhase(phase_data[[2*j,2*j+1]], color_index=(j%11),
125  line_style_index=(j%4),
126  label=str(blocks[i])
127  )
128  # plt.show()
129  fourier_dictionary = fourierSpectrum(run_name, phase_data[2*j])
130  plt.subplot(122)
131  prettyPlotFourier(fourier_dictionary,
132  color_index=(j%11),
133  line_style_index=(j%4),
134  label=str(blocks[j])
135  )
136 
137  plt.subplot(121)
138  plt.grid()
139  plt.ylim(-3, 2)
140  #plt.ylim(-2, 1)
141  plt.xlim(-3, 3)
142  #plt.xlim(-1, 3)
143  plt.subplot(122)
144  plt.grid()
145  plt.ylim(-0.01, 1.9)
146  #plt.ylim(-0.01, 0.5)
147  plt.xlim(-0.01, 4)
148  #plt.xlim(-0.01, 2)
149  plt.legend(title="Block:")
150  plt.suptitle("\$\\nu=\$" + phase_labels[i])
151  #plt.xlim(0,3.5)
152  plt.show()
153 
154 
155 def run():
156  if(len(sys.argv) > 1):
157  #plot_blocks(sys.argv[1])
158  plot_phase(sys.argv[1])
159 
160 
161 if __name__ == "__main__":
162  run()
def prettyPlotFourier(fourier_dictionary, y_label="\\, x_label="\f\", alpha=1.0, color_index=0, line_style_index=0, label="")
Definition: plotBlocks.py:75
def checkIfMultipleBlocks(block_data)
Definition: plotSetUp.py:30
def plot_phase(run_name)
Definition: plotBlocks.py:106
def plot_blocks(run_name)
Definition: plotBlocks.py:89
def prettyPlotPhase(phase_data, y_label="\\, x_label="\\dot{x}\", alpha=1.0, color_index=0, line_style_index=0, label="")
Definition: plotBlocks.py:55
def run()
Definition: plotBlocks.py:155
def loadPhaseFile(run_name, file_name, friction_folder="/friction_phase/", use_shared_names=False)
def createTimeStepValues(block_data, yaml_file)
Definition: plotSetUp.py:40
def loadFile(run_name, shared_names, selected='pad_position.csv')
def fourierSpectrum(run_name, data_vector)
def prettyPlotBlocks(time_steps, block_data, yaml_file, legend_title="", legend_loc="lower right", y_label="", x_label="\\)
Definition: plotBlocks.py:24
def setSvgLatexMatplotlibSettings(pyplot)
Definition: plotSetUp.py:11