-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_function.py
More file actions
executable file
·96 lines (78 loc) · 2.49 KB
/
read_function.py
File metadata and controls
executable file
·96 lines (78 loc) · 2.49 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# HERE WE READ DATA FROM OFFLINE AND ONLINE FILES
# AUTHOR: Jayro Martinez Cervero
def read_file(file_name):
"""
# FUNCTION: read_file(file_name)
# INPUT: Name of the file to read
# OUTPUT: Vertical & Horizontal components of the signal. Also a list with
# the label corresponding to each timepoint
# DESCRIPTION: Reads the data from a .txt file and returns it
# AUTHOR: Jayro Martinez Cervero
"""
# Open the file
file = open(file_name, 'r')
values = file.readlines()
# Load data into new_values
new_values = []
labels_tmp = []
hor_tmp = []
ver_tmp = []
for v in range(0,len(values)):
new_values.insert(v, values[v].split(','))
# Load data from new_values into labels, horizontal & vertical
for i in range(0,len(new_values)):
labels_tmp.append(new_values[i][0])
hor_tmp.append(new_values[i][2])
ver_tmp.append(new_values[i][7])
# Remove '[' and cast into float
for aux in range(0, len(labels_tmp)):
if labels_tmp[aux].find("[") != -1:
index = labels_tmp[aux].find("[")
labels_tmp[aux] = labels_tmp[aux].replace(labels_tmp[aux][index], '')
hor_tmp[aux] = float(hor_tmp[aux])
ver_tmp[aux] = float(ver_tmp[aux])
else:
hor_tmp[aux] = float(hor_tmp[aux])
ver_tmp[aux] = float(ver_tmp[aux])
return hor_tmp, ver_tmp, labels_tmp
def read_online_file(file_name):
"""
# FUNCTION: read_file(file_name)
# INPUT: Name of the file to read
# OUTPUT: Vertical & Horizontal components of the signal. Also a list with
# the label corresponding to each timepoint
# DESCRIPTION: Reads the data from a .txt file and returns it
# AUTHOR: Jayro Martinez Cervero
"""
# Open the file
print(file_name)
file = open(file_name, 'r')
values = file.readlines()
# Load data into new_values
new_values = []
labels_tmp = []
hor_tmp = []
ver_tmp = []
new_hor = []
new_ver = []
hor = []
ver = []
for v in range(0,len(values)):
new_values.insert(v, values[v].split(']'))
# Load data from new_values into labels, horizontal & vertical
for i in range(0,len(new_values)):
hor_tmp.append(new_values[i][0])
ver_tmp.append(new_values[i][1])
for j in range(0, len(hor_tmp)):
hor_tmp[j] = hor_tmp[j].replace(hor_tmp[j][0:2],'')
ver_tmp[j] = ver_tmp[j].replace(ver_tmp[j][0:3],'')
new_hor.insert(j, hor_tmp[j].split(','))
new_ver.insert(j, ver_tmp[j].split(','))
trial_hor = []
trial_ver = []
for k in range(0, len(new_hor[j])):
trial_hor.append(float(new_hor[j][k]))
trial_ver.append(float(new_ver[j][k]))
hor.append(trial_hor)
ver.append(trial_ver)
return hor, ver