Last active
May 22, 2019 18:27
-
-
Save Spandyie/a0f3d33c015c6226763595a5ffb64ccc to your computer and use it in GitHub Desktop.
Revisions
-
Spandyie revised this gist
May 22, 2019 . No changes.There are no files selected for viewing
-
Spandyie revised this gist
May 22, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,7 @@ def load_di_values(file_names,AceName,path): ###################################################################################### 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) -
Spandyie created this gist
May 22, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ 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= 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)