Skip to content
Snippets Groups Projects
Commit 029aa0a0 authored by milenabaj's avatar milenabaj
Browse files

acc only version

parent 8333f1ac
Branches
No related tags found
No related merge requests found
......@@ -10,35 +10,43 @@ from scipy.io import loadmat
import numpy as np
import pickle
def load_file(filename, min_index, max_index, data):
def load_file(filename, data, min_index = 0, max_index = -1, acc_only = False):
#print('Loading file: {0}'.format(filename))
defect_type = filename.split('_')[-2]
if acc_only:
# Get variables
f = loadmat(filename)
acc = f['acceleration'][min_index:max_index,:].reshape(1,-1)
# Update dictionary with the data from this file
data[filename] = {'acc':acc}
else:
# Get variables
f = loadmat(filename)
acc = f['acceleration'][min_index:max_index,:].reshape(1,-1)
time = f['time'][min_index:max_index,:].reshape(1,-1)
label = f['type'][min_index:max_index,:].reshape(1,-1)
severity = f['severity'][min_index:max_index,:].reshape(1,-1)
defect_type = filename.split('_')[-2]
# Update dictionary with the data from this file
data[filename] = {'time':time, 'acc':acc, 'true_labels':label, 'severity':severity, 'defect':defect_type}
return
# ========================================== #
# ========================================== #
# Define what to load
input_dir = 'data/Synth_data_20042020_speed40/'
min_index = 0
max_index = -1
file_pattern = '{0}*.mat'.format(input_dir)
acc_only = True
# Load data from mat files into python dictionary
data = {}
time_start = time.time()
for filename in glob.glob(file_pattern):
load_file(filename, min_index, max_index, data)
load_file(filename, data, min_index, max_index, acc_only)
time_elapsed = time.time() - time_start
print('=== Time to load from .mat files: {0:.2f} s'.format(time_elapsed))
......@@ -50,8 +58,10 @@ if not os.path.exists(out_dir):
os.makedirs(out_dir)
synth_data_string = input_dir.split('Synth_data')[-1].replace('/','')
if acc_only:
output_pkl_file = '{0}/Combined_synth_data{1}_acc_only.pickle'.format(out_dir, synth_data_string)
else:
output_pkl_file = '{0}/Combined_synth_data{1}.pickle'.format(out_dir, synth_data_string)
pik = open(output_pkl_file, 'wb')
pickle.dump(data, pik)
pik.close()
......@@ -67,9 +77,3 @@ file.close()
time_elapsed = time.time() - time_start
print('=== Time to load from .pickle file: {0:.2f} s'.format(time_elapsed))
sys.exit(0)
acc = acc.reshape(-1)
time = time.reshape(-1)
label = label.reshape(-1)
plt.plot(time,acc)
plt.plot(time, label)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment