#!/usr/bin/env python3 ''' Created on Wed Jun 10 14:15:02 2015 @author: suciud ''' ''' Copyright (c) 2015 Computational Biomechanics (CoBi) Core, Department of Biomedical Engineering, Cleveland Clinic Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------- csv_filereader.py DESCRIPTION: Python script to read a csv file and output matrixes and aritmetic values. REQUIREMENTS: Python (http://www.python.org) nptdms (https://pypi.python.org/pypi/npTDMS/) DEVELOPERS: Ahmet Erdemir Computational Biomodeling (CoBi) Core Department of Biomedical Engineering Lerner Research Institute Cleveland Clinic Cleveland, OH erdemira@ccf.org ''' import sys import csv import numpy import scipy from numpy import array import os numpy.seterr(divide='ignore', invalid='ignore') #Check that passing argument has a file and the program to run def USAGE(argv): print('\n') print('USAGE: ', argv[0], ' ') print('\n') return "null" #function that reads through the file and extract all frames, average them together, then scale them. def csv_filereader(filename): file = open(filename,'r') lines = file.readlines() found_first = False index = 0 findindex =0 scalefactor = 0.0 current_array=[[]] accum_array=numpy.zeros(shape=(44,44)) line=0 count=0 current_lists = [] x=0 #while the index is less than the total number of lines, and that the line is not a new line, or the end of the file while index0: #how many squares have pressure data on them x+=1 # the total area that pressure is taken from total_area=x*float(sensor) #the total are of the pressure pad possible_area=44*44*1.6129 #Print the matrix into a text file text_file = open("Output.txt", "w") ###see if this is correct text_file.write("\n Matrix:\n %s" % matrix) text_file.seek(0) text_file.close() #append the sensle area into a text file text_file = open("Output.txt", "a") ###see if this is correct text_file.write("\n Sensle Area: %s" % sensor) text_file.close() #append the pressure area into a text file text_file = open("Output.txt", "a") ###see if this is correct text_file.write("\n Pressure Area: %s" % total_area) text_file.close() #print(total_area) return total_area #get the equations and values of the integral from scipy import integrate def integral(x,a,b): return a*b #solve the integral setup def intsolve(filename): matrix=csv_filereader(filename) #the parameters of the integration are between the area and the maximum pressure args=(sesonrarea(filename),max_pressure(matrix)) maxp=max_pressure(matrix) #append the maximum pressure into a text file text_file = open("Output.txt", "a") ###see if this is correct' text_file.seek(0) text_file.write("\n Max Pressure: %s" % maxp) text_file.close() #run the integral results = integrate.quad(integral,0, pressure_area,args) #append the output integral into a text file text_file = open("Output.txt", "a") text_file.write("\n Integral: %s" %results[0]) text_file.close() #return the result of the integral return results[0] #make this script callable from the terminal, and run all of its functions if __name__ == "__main__": data = csv_filereader(sys.argv[-1]) max_pressures = max_pressure(data) data2=sesonrarea(sys.argv[-1]) pressure_area=pressure_area(sys.argv[-1]) intsolve=intsolve(sys.argv[-1])