Skip to content

Instantly share code, notes, and snippets.

@sagarhowal
Created January 14, 2018 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagarhowal/c5c745ba2c09e8bd535a562a89bc1759 to your computer and use it in GitHub Desktop.
Save sagarhowal/c5c745ba2c09e8bd535a562a89bc1759 to your computer and use it in GitHub Desktop.
from glob import glob
acc_files = glob(data_dir + 'acc_*.txt')
gyro_files = glob(data_dir + 'gyro_*.txt')
# Load data
data = tc.SFrame()
files = zip(sorted(acc_files), sorted(gyro_files))
for acc_file, gyro_file in files:
exp_id = int(acc_file.split('_')[1][-2:])
user_id = int(acc_file.split('_')[2][4:6])
# Load accel data
sf = tc.SFrame.read_csv(acc_file, delimiter=' ', header=False, verbose=False)
sf = sf.rename({'X1': 'acc_x', 'X2': 'acc_y', 'X3': 'acc_z'})
sf['exp_id'] = exp_id
sf['user_id'] = user_id
# Load gyro data
gyro_sf = tc.SFrame.read_csv(gyro_file, delimiter=' ', header=False, verbose=False)
gyro_sf = gyro_sf.rename({'X1': 'gyro_x', 'X2': 'gyro_y', 'X3': 'gyro_z'})
sf = sf.add_columns(gyro_sf)
# Calc labels
exp_labels = labels[labels['exp_id'] == exp_id][['activity_id', 'start', 'end']].to_numpy()
sf = sf.add_row_number()
sf['activity_id'] = sf['id'].apply(lambda x: find_label_for_containing_interval(exp_labels, x))
sf = sf.remove_columns(['id'])
data = data.append(sf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment