-
Notifications
You must be signed in to change notification settings - Fork 1
/
cut_data_samples.py
59 lines (45 loc) · 1.77 KB
/
cut_data_samples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from file_importing import get_newer_files
import pandas as pd
import numpy as np
'''
A function which takes the data samples from the Bite and Blink Data analysis folder and makes them the same length.
The function accounts for the sample length to ensure the action is preserved.
'''
def cut_samples():
df = pd.DataFrame(columns=['c1', 'c2', 'c3', 'c4'])
bites, blinks = get_newer_files()
bite_tuples = []
blink_tuples = []
for b in bites:
length = b[(len(b) - 12)] # logic issue with code seeing 10 as 0. Don't have a more elegant solution,
# this is temporary
if length == "0":
length = 10
bite_tuples.append((b, length))
for b in blinks:
length = b[(len(b) - 12)]
if length == "0":
length = 10
blink_tuples.append((b, length))
for blink in blinks:
d = pd.read_csv(blink)
df = df.append({'c1': np.array(d.c1), 'c2': np.array(d.c2), 'c3': np.array(d.c3), 'c4': np.array(d.c4)},
ignore_index=True)
for bite in bites:
d = pd.read_csv(bite)
df = df.append({'c1': np.array(d.c1), 'c2': np.array(d.c2), 'c3': np.array(d.c3), 'c4': np.array(d.c4)},
ignore_index=True)
# Temporary code which shows the number of samples.
# These vary even within samples of the same labelled length. Discuss at next meeting.
idx = 0
for file, length in bite_tuples:
print(len(df.loc[idx][0]))
print(str(length) + " seconds")
idx += 1
for file, length in blink_tuples:
print(len(df.loc[idx][0]))
print(str(length) + " seconds")
idx += 1
# TODO: Fix df.append, functionality will be deprecated soon from Pandas.
# TODO: Check the number of samples
cut_samples()