Skip to content

Instantly share code, notes, and snippets.

@Spandyie
Last active May 22, 2019 18:27
Show Gist options
  • Save Spandyie/a0f3d33c015c6226763595a5ffb64ccc to your computer and use it in GitHub Desktop.
Save Spandyie/a0f3d33c015c6226763595a5ffb64ccc to your computer and use it in GitHub Desktop.
The following python code compiles damage index files generated by SHMPAtch software into a single spreadsheet. SHMPatch software is Acellent Technologies's proprietary software. #Structuralhealthmonitoring
import os
import sys
import glob
import numpy as np
from pandas import DataFrame
import pandas as pd
def load_data_file():
"""reads the names of the files in data folder"""
path = os.getcwd()
data_directory = path + "\\data"
os.chdir(data_directory)
file_names=[]
for filenm in glob.glob("*.dat"):
file_names.append(filenm)
return file_names, path
###################################################################################
def load_di_values(file_names,AceName,path):
"""Stores the DI values of the data present in Data folder"""
############################################################
################Read Acefile
##########################################################
acefile_path = path +"\\"+ AceName
with open(acefile_path,"r") as acefnm:
acefile=[]
for xace in acefnm:
acefile.append(xace)
dfn_file=acefile[2][21:]
dfn_file_path = path+"\\dfn\\"+ dfn_file[:-1]
with open(dfn_file_path,"r") as dfn_inp:
dfnvalues=[]
for xdfn in dfn_inp:
dfnvalues.append(xdfn.split())
dfnMatrix = dfnvalues[1:]
frequency = [np.int(freq[0]) for freq in dfnMatrix] ## extracting frequency
actuator = [ act[3] for act in dfnMatrix] ## extracting actuator
sensor = [sens[4] for sens in dfnMatrix] ## extracting sensor
uniqFreq = np.unique(frequency)
###################################################################################
DIMatrix ={}
for frq in uniqFreq:
DIMatrix[str(frq)]=[] # create seperate tuple for each frequency
for x in file_names:
DIvalue=[]
x_path = path + "\\rpt\\" + x[:-4]+"_"+str(frq)+"kHz"+".dix"
with open(x_path, "r") as fileinp:
for line in fileinp:
temp_line= line.split()
DIvalue.append(np.float64(temp_line[3]))
DIMatrix[str(frq)].append(np.array(DIvalue))
return DIMatrix, actuator, sensor
######################################################################################
def write_excel_file(DIMatrix,DI_file, path):
for key in DIMatrix:
act_sens= list(zip(actuator,sensor))
act_sens.insert(0,'File Name')
head =[('File Name')]
head.append(act_sens)
df_di = DataFrame(DIMatrix[key])
df_filename = DataFrame(DI_file)
df = pd.concat([df_filename,df_di], axis=1)
filename = path + "\\DI" + "_"+ str(key) + ".xlsx"
#df_filename.to_excel(writer,sheet_name='sheet1',startrow=0,startcol =0)
df.to_excel(filename,sheet_name='sheet1',startrow=0, index=False, header = act_sens)
#####################################################################################
if __name__== "__main__":
ace_file_name = sys.argv[1]
DI_file, path = load_data_file()
DI_value, actuator, sensor = load_di_values(DI_file,ace_file_name,path)
write_excel_file(DI_value, DI_file, path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment