Skip to content

Instantly share code, notes, and snippets.

@boulama
Last active October 21, 2022 03:22
Show Gist options
  • Save boulama/bc1174fd2ee1be5b92b894938208c251 to your computer and use it in GitHub Desktop.
Save boulama/bc1174fd2ee1be5b92b894938208c251 to your computer and use it in GitHub Desktop.
Code used to analyze flexure (flexure.py) and Impact (impact.py) from experimental data.
import pandas as pd
import matplotlib.pyplot as plt
import re
def camel_case_split(str):
return re.sub(r'((?<=[a-z])[A-Z]|(?<!\A)[A-Z](?=[a-z]))', r' \1', str)
f = [
['2in_3PtLoading.csv', '3pt', 'D2344', 25.4, 3.17],
['5in_3PtLoading.csv', '3pt', 'D7264', 25.4, 3.17],
['5in_4PtLoading.csv', '4pt', 'D7264', 1, 1]
]
i = 0
for n in f:
width = n[3]
thick = n[4]
dataset = pd.read_csv('./fimp/' + n[0])
pin_loads = dataset[' "Load (N)"'].abs()
max_load = pin_loads.max()
max_load_index = pin_loads[pin_loads == max_load].index[0]
if n[2] == 'D2344': # sort beam
strength = (3 * max_load) / 4*width*thick
print(f'Strength({n[2]}): {strength} GPa')
else:
print(f'Modulus of Rupture ({n[2]}: {max_load} N')
delta = 0
if i == 2:
delta = 70
if i == 0:
dataset = dataset.iloc[130:, :]
delta = 180
dataset = dataset.head(max_load_index - delta)
time = dataset['Time']
pin_loads = dataset[' "Load (N)"'].abs()
pin_position = dataset[' "Position (mm)"'].abs()
# plt.plot(pin_position, pin_loads, 'r-')
#
# plt.xlabel('Displacement (mm)')
# plt.ylabel('Load (N)')
# plt.title(camel_case_split(n[0].replace('_', ' ')).strip('.csv'))
# plt.show()
i += 1
import pandas as pd
import matplotlib.pyplot as plt
import re
def camel_case_split(str):
return re.sub(r'((?<=[a-z])[A-Z]|(?<!\A)[A-Z](?=[a-z]))', r' \1', str)
f = [
['Sp1_PVC_Impact.csv', 'pvc', 'D2344', 25.4, 3.17],
['Sp2_Carbon Fiber_Impact.csv', 'cf', 'D7264', 25.4, 3.17]
]
i = 0
for n in f:
width = n[3]
thick = n[4]
dataset = pd.read_csv('./fimp/' + n[0])
loads = dataset['Load (lb)']
max_load = loads.max()
max_load_index = loads[loads == max_load].index[0]
delta = 0
l = 2000
# if i == 2:
# delta = 70
if i == 0:
l = 1530
print(max_load_index)
dataset = dataset.head(l - delta)
time = dataset['Time (ms)']
loads = dataset['Load (lb)']
energy = dataset['Velocity (ft/sec)']
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(time, energy, 'g-')
ax2.plot(time, loads, 'b-')
ax1.set_ylabel('energy (lb-ft)', color='g')
ax1.set_xlabel('time (ms)')
ax2.set_ylabel('force (lb)', color='b')
ax1.title.set_text(camel_case_split(n[0].replace('_', ' ')).strip('.csv'))
plt.show()
# energy vs time
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment