Clean the digitized accelaration curve¶
In [23]:
Copied!
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
In [24]:
Copied!
path = "./"
file = "sled_acceleration_25_5_u.csv"
file = open(path+file)
digitized = np.loadtxt(file, delimiter=',', skiprows=2)
path = "./"
file = "sled_acceleration_25_5_u.csv"
file = open(path+file)
digitized = np.loadtxt(file, delimiter=',', skiprows=2)
In [25]:
Copied!
digitized
digitized
Out[25]:
array([[ 0.00000000e+00, 0.00000000e+00],
[ 5.32746300e-03, 8.05591324e+01],
[ 8.72583800e-03, 4.18322156e+01],
[ 1.22501260e-02, 4.61318983e+01],
[ 1.63566580e-02, 4.93925117e+01],
[ 2.36792060e-02, 5.16118228e+01],
[ 2.95285610e-02, 5.04199200e+01],
[ 4.00679940e-02, 5.18946640e+01],
[ 4.62147660e-02, 5.23345565e+01],
[ 5.23598010e-02, 5.21809787e+01],
[ 5.90957640e-02, 5.39556832e+01],
[ 6.52373260e-02, 5.26151648e+01],
[ 6.90338490e-02, 4.99413228e+01],
[ 7.48814670e-02, 4.81559497e+01],
[ 8.21962000e-02, 4.77046443e+01],
[ 8.71576440e-02, 4.31010314e+01],
[ 9.24230190e-02, 4.23547275e+01],
[ 9.85680540e-02, 4.22011497e+01],
[ 1.06760277e-01, 4.16007324e+01],
[ 1.19633026e-01, 4.04028751e+01],
[ 1.27820473e-01, 3.81704143e+01],
[ 1.35133469e-01, 3.71256386e+01],
[ 1.42736935e-01, 3.53387768e+01],
[ 1.47393147e-01, 2.64327520e+01],
[ 1.48535056e-01, 1.66394990e+01],
[ 1.50237934e-01, -1.46283491e+00],
[ 1.52523489e-01, -2.04558706e+01],
[ 1.59007624e-01, -4.73436496e+00],
[ 1.63682506e-01, -7.26058360e+00],
[ 1.69239653e-01, -8.30387071e+00],
[ 1.74512409e-01, -6.52792561e+00],
[ 1.81539711e-01, -5.19857190e+00],
[ 1.90028048e-01, -4.61229665e+00],
[ 1.95581723e-01, -6.84252443e+00],
[ 2.01434117e-01, -6.99585414e+00],
[ 2.11682211e-01, -5.07575927e+00],
[ 2.18121624e-01, -4.63611485e+00],
[ 2.24843259e-01, -7.75754057e+00],
[ 2.30112107e-01, -7.31690373e+00],
[ 2.35094392e-01, -4.79887260e+00],
[ 2.41529898e-01, -5.69453645e+00],
[ 2.46790931e-01, -7.92451613e+00],
[ 2.54109571e-01, -7.04051328e+00],
[ 2.62600080e-01, -5.71240011e+00],
[ 2.72549888e-01, -5.72083572e+00],
[ 2.79570677e-01, -6.61699578e+00],
[ 2.86009656e-01, -6.32571895e+00],
[ 2.93330034e-01, -4.84824576e+00],
[ 3.01519217e-01, -6.48723617e+00],
[ 3.08540874e-01, -7.08666106e+00],
[ 3.14981591e-01, -6.20191389e+00]])
In [26]:
Copied!
plt.plot(digitized[:,0], digitized[:,1])
plt.plot(digitized[:,0], digitized[:,1])
Out[26]:
[<matplotlib.lines.Line2D at 0x1feb2103ac0>]
The curve has intial region with negligible acceleration. Remove this region
Unit Conversion¶
The acceleration is reported in units of g. Converting it to mm/ms^2
In [27]:
Copied!
# Convert time to ms
digitized[:,0] = digitized[:,0]*1000
# Convert to mm/ms^2
digitized[:,1] = digitized[:,1]*1e-3
plt.plot(digitized[:,0], digitized[:,1])
# Convert time to ms
digitized[:,0] = digitized[:,0]*1000
# Convert to mm/ms^2
digitized[:,1] = digitized[:,1]*1e-3
plt.plot(digitized[:,0], digitized[:,1])
Out[27]:
[<matplotlib.lines.Line2D at 0x1feb2e49910>]
In [28]:
Copied!
last_Time_Step = round(digitized[-1,0])
last_Time_Step = round(digitized[-1,0])
In [29]:
Copied!
last_Time_Step
last_Time_Step
Out[29]:
315
Resampling the curve for LS-Dyna Input¶
In [30]:
Copied!
# Sorting the vectors based on time, just in case there are closeby points that are interchanged during digitizing. To ensure that interpolation is not messed up
digitized_sort = digitized[np.argsort(digitized[:,0])]
plt.plot(digitized_sort[:,0], digitized_sort[:,1])
# Sorting the vectors based on time, just in case there are closeby points that are interchanged during digitizing. To ensure that interpolation is not messed up
digitized_sort = digitized[np.argsort(digitized[:,0])]
plt.plot(digitized_sort[:,0], digitized_sort[:,1])
Out[30]:
[<matplotlib.lines.Line2D at 0x1feb223fb20>]
The resampling follows the example at scipy: https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html
In [31]:
Copied!
from scipy.interpolate import interp1d
from scipy.interpolate import interp1d
In [32]:
Copied!
f1 = interp1d(digitized_sort[:,0], digitized_sort[:,1])
f1 = interp1d(digitized_sort[:,0], digitized_sort[:,1])
In [33]:
Copied!
x_new = np.linspace(0,last_Time_Step-1,last_Time_Step)
y_new = f1(x_new)
x_new = np.linspace(0,last_Time_Step-1,last_Time_Step)
y_new = f1(x_new)
In [34]:
Copied!
digitized_resampled = np.stack((x_new, y_new), axis=-1)
# Remove the negligible offset in the first row
#acc8A_resampled[0,1] = round(acc8A_resampled[0,1])
plt.plot(digitized_resampled[:,0], digitized_resampled[:,1])
digitized_resampled = np.stack((x_new, y_new), axis=-1)
# Remove the negligible offset in the first row
#acc8A_resampled[0,1] = round(acc8A_resampled[0,1])
plt.plot(digitized_resampled[:,0], digitized_resampled[:,1])
Out[34]:
[<matplotlib.lines.Line2D at 0x1fec97b9a30>]
In [44]:
Copied!
np.savetxt('Resampled.csv', digitized_resampled, fmt='%i, %1.5f', delimiter=',')
np.savetxt('Resampled.csv', digitized_resampled, fmt='%i, %1.5f', delimiter=',')