import numpy as np import os AU = ["Person", "Case", "Confidence", "AU01", "AU02", "AU04", "AU05", "AU06", "AU07", "AU09","AU10","AU12","AU14","AU15","AU17","AU20","AU23", "AU25","AU26", "AU45"] # folder where output csv files of OpenFace are stored folder = '/home/valapil/Project/ForkCausal_Adithya/csv_files' csv_files = [file for file in os.listdir(folder) if file.endswith('.csv')] # load the offset values offset = np.load(f'/home/valapil/Project/ForkCausal_Adithya/offset_values.npy') length = {} same = np.unique(offset[1:, 0]) for i in same: same_rows = offset[offset[:, 0] == i] length[i] = max(abs(int(same_rows[0][2]) - int(same_rows[0][1])), abs(int(same_rows[1][2]) - int(same_rows[1][1]))) for file in csv_files: base_name, extension = os.path.splitext(file) new_name = base_name.split('.')[0] f1 = new_name[:-2] f2 = new_name[-1:] file_path = os.path.join(folder, file) len = length[new_name[:-3] + new_name[-1]] start = np.where(offset[1:, 3] == new_name)[0][0] start = int(offset[start+1, 1]) data_all = np.genfromtxt(file_path, delimiter=',', skip_header=1) data = data_all[start:len-200, 679:696] selected_columns = np.hstack((np.full((data.shape[0], 2), [f1, f2]), data_all[start:len-200, [3]], data)) AU = np.row_stack((AU, selected_columns)) # save each offset data here np.save(f'/home/valapil/Project/ForkCausal_Adithya/data/{new_name}.npy', data) # save all offset data with the particular case and confidence value here np.save(f'/home/valapil/Project/ForkCausal_Adithya/processed_data.npy', AU)