My Project
plotPadStep.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_diverging_long as colors_long, \
6  linestyles, \
7  createTimeStepValues, \
8  createSliderVelocityStepValues
9 import sys
10 from matplotlib import pyplot as plt
11 from mpl_toolkits.mplot3d import Axes3D
12 from matplotlib.collections import PolyCollection
13 from matplotlib import colors
14 #from matplotlib import cm
15 
16 
18 
19 
21  yaml_file
22 ):
23  start_speed_continuous = yaml_file["Parameters"]["start_speed_continuous"]
24  end_speed_continuous = yaml_file["Parameters"]["end_speed_continuous"]
25 
26  direction = end_speed_continuous - start_speed_continuous
27 
28  if(direction < 0):
29  return 3
30  else:
31  return 4
32 
33 
34 def prettyPlotPad(
35  time_steps,
36  pad_data,
37  yaml_file,
38  y_label="\$x\$",
39  x_label="\$t\$",
40  alpha=1.0
41 ):
42  color_index = choseColourFromDirection(yaml_file)
43  plt.plot(time_steps, pad_data,
44  color=colors_short[color_index],
45  linestyle=linestyles[0],
46  label="Pad",
47  linewidth=0.4,
48  alpha=alpha
49  )
50 
51  plt.ylim(-1.6, 0.6)
52  plt.ylabel(y_label)
53  plt.xlabel(x_label)
54 
55 
56 def plot3D(
57  run_name
58 ):
59  import numpy as np
60  from matplotlib import cm
61  yaml_file = loadYaml(run_name)
62  pad_position = loadFile(run_name, yaml_file, file_name="pad_position")
63  start_velocity = yaml_file["Parameters"]["slider_speed"]
64  increment = yaml_file["Parameters"]["increment"]
65 
66  zs = range(20)
67  verts = []
68  amplitudes = []
69  frequencies = []
70  #plt.figure()
71  fig = plt.figure()
72  ax = fig.add_subplot(111)
73  for i in range(0, 150):
74  #plt.subplot(121)
75  phase_data = loadPhaseFile(run_name, "pad_phase_" + str(i))
76 
77  fourier_dictionary = fourierSpectrum(run_name, phase_data[0])
78  amount_data_half = len(phase_data[0])//5
79  verts.append(list(zip(fourier_dictionary['x_values'], fourier_dictionary['y_values'])))
80  amplitudes.append(fourier_dictionary['y_values'][1:])
81  frequencies.append(fourier_dictionary['x_values'][1:])
82  # plt.plot(fourier_dictionary['x_values'], label=str(i))
83  # plt.legend()
84  # plt.show()
85 
86 
87  cax = ax.matshow(amplitudes, cmap="ocean_r",
88  extent=[frequencies[0][0], frequencies[0][-1], 1.49, 0.0])
89  ax.set_xlabel("\$f\$")
90  ax.set_ylabel("\$\\nu\$")
91  cbar = fig.colorbar(cax)
92  cbar.set_label("\$A\$", rotation=270)
93  plt.show()
94 
95 
96 def plotPhase3D(
97  run_name
98 ):
99  import numpy as np
100  from matplotlib import cm
101  yaml_file = loadYaml(run_name)
102  pad_position = loadFile(run_name, yaml_file, file_name="pad_position")
103  start_velocity = yaml_file["Parameters"]["slider_speed"]
104  increment = yaml_file["Parameters"]["increment"]
105 
106  zs = range(20)
107  verts = []
108  amplitudes = []
109  frequencies = []
110  #plt.figure()
111 
112  jet = plt.get_cmap('viridis')
113  cNorm = colors.Normalize(vmin=0, vmax=1.49)
114  scalarMap = cm.ScalarMappable(norm=cNorm, cmap=jet)
115  fig = plt.figure()
116  ax = fig.gca(projection='3d')
117  for i in range(0, 150):
118  velocity = start_velocity+increment*i
119  phase_data = loadPhaseFile(run_name, "pad_phase_" + str(i))
120  alpha = 0.7
121  ax.plot(phase_data[0], phase_data[1], alpha=alpha,
122  zs=(velocity), color=scalarMap.to_rgba(velocity))
123 
124  ax.view_init(elev=2.5, azim=-45)
125  plt.rcParams["savefig.bbox"] = "tight"
126  ax.set_ylabel("\$x\$")
127  ax.set_xlabel("\$\dot{x}\$")
128  ax.set_zlabel("\$\\nu\$")
129  ax.set_yticks(np.arange(-0.6,0.6,0.3))
130  plt.show()
131  plt.rcParams["savefig.bbox"] = "standard"
132 
133 
134 def prettyPlotPhase(
135  phase_data,
136  y_label="\$x\$",
137  x_label="\$\\dot{x}\$",
138  alpha=1.0,
139  color_index=0,
140  line_style_index=0,
141  label=""
142 ):
143  plt.plot(phase_data[1], phase_data[0],
144  color=colors_short[color_index],
145  linestyle=linestyles[line_style_index],
146  label=label,
147  linewidth=0.9,
148  alpha=alpha
149  )
150  plt.ylabel(y_label)
151  plt.xlabel(x_label)
152 
153 
155  fourier_dictionary,
156  y_label="\$A\$",
157  x_label="\$f\$",
158  alpha=1.0,
159  color_index=0,
160  line_style_index=0,
161  label=""
162 ):
163 
164  plt.plot(fourier_dictionary["x_values"][1:],
165  fourier_dictionary["y_values"][1:],
166  color=colors_short[color_index],
167  linestyle=linestyles[line_style_index],
168  label=label)
169  #plt.xlim(0.0, 2.0)
170  plt.ylabel(y_label)
171  plt.xlabel(x_label)
172 
173 
174 def plotPad(
175  run_name,
176  alpha=1.0
177 ):
178  yaml_file = loadYaml(run_name)
179  pad_position = loadFile(run_name, yaml_file, file_name="pad_position")
180  #pad_velocity = loadFile(run_name, yaml_file, file_name="pad_velocity")
181  time_steps = createSliderVelocityStepValues(pad_position, yaml_file)
182 
183  prettyPlotPad(time_steps, pad_position, yaml_file,
184  x_label="\$\\nu\$", alpha=alpha)
185 
186 
187 def plotPhase(
188  run_name
189 ):
190  yaml_file = loadYaml(run_name)
191  #pad_position = loadFile(run_name, yaml_file, file_name="pad_position")
192  start_velocity = yaml_file["Parameters"]["slider_speed"]
193  increment = yaml_file["Parameters"]["increment"]
194 
195  slider_velocities = [8, 11, 67, 72, 111, 130]
196  phase_labels = [str(round(abs(increment*velocity),2)) for velocity in slider_velocities]
197  if(increment < 0):
198  slider_velocities = [int(149 - slider_velocity) for slider_velocity in slider_velocities]
199 
200  plt.figure()
201  for i, velocity in enumerate(slider_velocities):
202  phase_data = loadPhaseFile(run_name, "pad_phase_" + str(velocity))
203  plt.subplot(121)
204  prettyPlotPhase(phase_data, color_index=-1,
205  line_style_index=(i%4),
206  label=phase_labels[i])
207  fourier_dictionary = fourierSpectrum(run_name, phase_data[0])
208  plt.subplot(122)
209  prettyPlotFourier(fourier_dictionary,
210  color_index=-1,
211  line_style_index=(i%4),
212  label="Pad"
213  )
214  plt.subplot(121)
215  plt.grid()
216  plt.ylim(-0.6, 0)
217  #plt.ylim(-0.6, -0.5)
218  plt.xlim(-0.1, 0.1)
219  #plt.xlim(-0.05, 0.05)
220  plt.subplot(122)
221  plt.grid()
222  plt.ylim(-0.01, 0.1)
223  #plt.ylim(-0.001, 0.02)
224  plt.xlim(-0.01, 4)
225  #plt.xlim(-0.01, 2)
226  plt.legend()
227  plt.suptitle("\$\\nu=\$" + phase_labels[i])
228  plt.show()
229 
230 
231 def plotFourier(
232  run_name
233 ):
234  yaml_file = loadYaml(run_name)
235  #pad_position = loadFile(run_name, yaml_file, file_name="pad_position")
236  start_velocity = yaml_file["Parameters"]["slider_speed"]
237  increment = yaml_file["Parameters"]["increment"]
238 
239  plt.figure()
240  for i in range(0, 150):
241  phase_data = loadPhaseFile(run_name, "pad_phase_" + str(i))
242  fourier_dictionary = fourierSpectrum(run_name, phase_data[0])
243  prettyPlotFourier(fourier_dictionary,
244  color_index=(i%11),
245  line_style_index=(i%4))
246  plt.suptitle("\$\\nu=\$" + str(start_velocity + i*increment))
247  #plt.legend()
248  plt.xlim(0,1.5)
249  plt.show()
250 
251 
252 
253 def plotComparePads(
254  run_names
255 ):
256  for run_name in run_names:
257  plotPad(run_name, alpha=0.7)
258  plt.show()
259 
260 
261 
262 def run():
263  if(len(sys.argv) == 2):
264  plotPhase(sys.argv[1])
265  #plotFourier(sys.argv[1])
266  #plot3D(sys.argv[1])
267  #plotPhase3D(sys.argv[1])
268  elif(len(sys.argv) > 2):
269  plotComparePads(sys.argv[1:])
270 
271 
272 if __name__ == "__main__":
273  run()
def plotComparePads(run_names)
Definition: plotPadStep.py:255
def createSliderVelocityStepValues(block_data, yaml_file, step_as_continous=False)
Definition: plotSetUp.py:61
def plotPad(run_name, alpha=1.0)
Definition: plotPadStep.py:177
def plotPhase3D(run_name)
Definition: plotPadStep.py:98
def prettyPlotPad(time_steps, pad_data, yaml_file, y_label="\\, x_label="\t\", alpha=1.0)
Definition: plotPadStep.py:41
def prettyPlotFourier(fourier_dictionary, y_label="\\, x_label="\f\", alpha=1.0, color_index=0, line_style_index=0, label="")
Definition: plotPadStep.py:162
def plotPhase(run_name)
Definition: plotPadStep.py:189
def loadPhaseFile(run_name, file_name, friction_folder="/friction_phase/", use_shared_names=False)
def plot3D(run_name)
Definition: plotPadStep.py:58
def plotFourier(run_name)
Definition: plotPadStep.py:233
def loadFile(run_name, shared_names, selected='pad_position.csv')
def fourierSpectrum(run_name, data_vector)
def choseColourFromDirection(yaml_file)
Definition: plotPadStep.py:22
def prettyPlotPhase(phase_data, y_label="\\, x_label="\\dot{x}\", alpha=1.0, color_index=0, line_style_index=0, label="")
Definition: plotPadStep.py:142
def setSvgLatexMatplotlibSettings(pyplot)
Definition: plotSetUp.py:11