mirror of
https://github.com/balajsra/EECS-442-WN19-DIC-Project.git
synced 2025-09-02 17:03:15 +00:00
Modify main.py
* Add new class SpecimenDimensions to hold dimensional information. * Add stress variable to FrameData class. * rename calc_stress function to read_file * Add data filepath as input to read_file function * read_file function now calculates stress from cross-sectional area of specimen and load from each frame. * read_file function now returns dictionary (indexed by frame number) of FrameData objects that have load, displacement, and stress data. Also returns SpecimenDimensions object that holds width, thickness, gauge length, and overall length.
This commit is contained in:
52
src/main.py
52
src/main.py
@@ -1,31 +1,37 @@
|
||||
#############################################
|
||||
# EECS 442: Computer Vision - W19 #
|
||||
#############################################
|
||||
# Authors: Sravan Balaji & Kevin Monpara #
|
||||
# Filename: main.py #
|
||||
# Description: #
|
||||
#############################################
|
||||
|
||||
import numpy as np
|
||||
#############################################################
|
||||
# EECS 442: Computer Vision - W19 #
|
||||
#############################################################
|
||||
# Authors: Sravan Balaji & Kevin Monpara #
|
||||
# Filename: main.py #
|
||||
# Description: #
|
||||
# Read data file to get specimen dimensions. #
|
||||
# Read in load and displacement data for each frame. #
|
||||
# Calculate stress from load and cross-sectional area. #
|
||||
#############################################################
|
||||
|
||||
|
||||
class FrameData:
|
||||
load = 0 # Load in N
|
||||
disp = 0 # Displacement in mm
|
||||
stress = 0 # Stress in MPa
|
||||
|
||||
def __init__(self, load, disp):
|
||||
def __init__(self, load, disp, stress):
|
||||
self.load = load
|
||||
self.disp = disp
|
||||
self.stress = stress
|
||||
|
||||
|
||||
def calc_stress():
|
||||
file = open("../Section001_Data.txt", "r")
|
||||
|
||||
class SpecimenDimensions:
|
||||
w = 0 # Specimen Width in mm
|
||||
t = 0 # Specimen Thickness in mm
|
||||
gl = 0 # Specimen Gauge Length in mm
|
||||
ol = 0 # Specimen Overall Length in mm
|
||||
|
||||
|
||||
def read_file(filepath):
|
||||
file = open(filepath, "r")
|
||||
|
||||
specimen = SpecimenDimensions()
|
||||
load_disp_data = dict()
|
||||
|
||||
data_start = -1
|
||||
@@ -34,19 +40,19 @@ def calc_stress():
|
||||
for line in file:
|
||||
if "Width" in line:
|
||||
index = line.find("\t")
|
||||
w = float(line[index + 1:])
|
||||
specimen.w = float(line[index + 1:])
|
||||
|
||||
if "Thickness" in line:
|
||||
index = line.find("\t")
|
||||
t = float(line[index + 1:])
|
||||
specimen.t = float(line[index + 1:])
|
||||
|
||||
if "Gauge Length" in line:
|
||||
index = line.find("\t")
|
||||
gl = float(line[index + 1:])
|
||||
specimen.gl = float(line[index + 1:])
|
||||
|
||||
if "Overall Length" in line:
|
||||
index = line.find("\t")
|
||||
ol = float(line[index + 1:])
|
||||
specimen.ol = float(line[index + 1:])
|
||||
|
||||
if "Frame #" in line:
|
||||
data_start = 2
|
||||
@@ -60,13 +66,19 @@ def calc_stress():
|
||||
if in_frame_data:
|
||||
if line != '\t\t\n':
|
||||
frame_num_str, load_str, disp_str = line.split("\t")
|
||||
|
||||
frame_num = int(frame_num_str)
|
||||
|
||||
load = float(load_str)
|
||||
disp = float(disp_str)
|
||||
load_disp_data[frame_num] = FrameData(load, disp)
|
||||
stress = load / (specimen.w * specimen.t)
|
||||
|
||||
print("Done")
|
||||
load_disp_data[frame_num] = FrameData(load, disp, stress)
|
||||
|
||||
file.close()
|
||||
|
||||
return specimen, load_disp_data
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
calc_stress()
|
||||
specimen, load_disp_data = read_file("../Section001_Data.txt")
|
||||
|
Reference in New Issue
Block a user