%matplotlib inline
import csv, math, os
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams['figure.figsize'] = (16.0, 10.0)
# Function to read in the data
def read_data(filename):
# Read in data
a = np.loadtxt(filename, delimiter=";", skiprows=2)
# Sort on the 5th column, return the result
return a[a[:,4].argsort()]
# Some constants that can be used in the remainder of the code
area = (3.5**2)*math.pi # cross section area of the sample
cutoff_peak = 0.005 # we assume the load peak is at a strain (x-value) lower than this value
cutoff_min = 0.05 # we assume the minimum after the peak is at a strain lower than this value
a = "hej";
# Function to calculate the strain and load from the loaded data
def calc_strain_load(data):
strain = data[:,4]
load = data[:,2]
return strain,load
# Function to compute the peak strain and return the result
def find_peak(strain, load):
i = -1
peak_y = 0
while peak_y < 0.005:
i = i+1
peak_y = strain[i]
peak_x = load[i-1]
peak_y = strain[i-1]
print(strain[i-1])
return peak_x,peak_y
# Function to compute E-modul and return the result
def find_gradient(strain, load):
e_modul = (strain.max()-strain.min())/(load[strain.argmax()]-load[strain.argmin()])
return e_modul
# Function to compute R_el and return the result
def find_strain_limit(strain, load):
# .....
return limit_x,limit_y
def process_file(filename):
data = read_data(filename)
strain,load = calc_strain_load(data)
peak_x,peak_y = find_peak(strain,load)
gradient = find_gradient(strain,load)
#limit_x,limit_y = find_limit(strain,load)
# print gradient
print(gradient)
# plot strain and load
plt.plot()
plt.text(1, 1, r'$\mu=100,\ \sigma=15$')
# mark peak and limit on the graph
process_file("Specimen_RawData_1.csv")