-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget-data.py
109 lines (93 loc) · 2.17 KB
/
get-data.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
import argparse
import os
import random
import time
import numpy as np
import pandas as pd
from brainflow.board_shim import BoardIds, BoardShim, BrainFlowInputParams
def parseargs():
parser = argparse.ArgumentParser()
parser.add_argument(
"-p",
"--serial-port",
type=str,
help="serial port for reciever",
required=False,
default="/dev/ttyUSB0",
)
parser.add_argument(
"-f",
"--file",
type=str,
help="file path to save data to",
required=False,
default="data.csv",
)
parser.add_argument(
"-t",
"--time",
type=float,
help="Length of time (seconds) to read data for",
required=False,
default=10,
)
parser.add_argument(
"-b",
"--blink",
action="store_true",
help="Record blinks",
)
args = parser.parse_args()
return args
def main():
args = parseargs()
BoardShim.enable_dev_board_logger()
params = BrainFlowInputParams()
params.serial_port = args.serial_port
board_id = BoardIds.CYTON_BOARD
board = BoardShim(board_id, params)
board.prepare_session()
board.start_stream()
if args.blink:
start = time.time()
while time.time() - start < args.time:
time.sleep(2)
print("blink")
board.insert_marker(1)
time.sleep(0.5)
os.system("clear")
else:
time.sleep(args.time)
data = board.get_board_data() # get all data and remove it from internal buffer
board.stop_stream()
board.release_session()
df = pd.DataFrame(np.transpose(data))
df.columns = [
"packet",
"eeg1",
"eeg2",
"eeg3",
"eeg4",
"eeg5",
"eeg6",
"eeg7",
"eeg8",
"accel1",
"accel2",
"accel3",
"other1",
"other2",
"other3",
"other4",
"other5",
"other6",
"other7",
"analog1",
"analog2",
"analog3",
"timestamp",
"marker",
]
df.to_csv(args.file, index=True)
if __name__ == "__main__":
main()