-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataCollect.py
56 lines (45 loc) · 1.67 KB
/
DataCollect.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 11 13:00:54 2017
@author: omrinachmani
"""
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 10 21:35:39 2017
@author: omrinachmani
"""
import numpy as np
from pylsl import StreamInlet, resolve_stream
import time
def getData(runtime=60):
print('looking for an EEG stream...')
runTime = runtime
streams = resolve_stream('type', 'EEG')
if len(streams) ==0:
raise(RunTimeError('Cant find EEG stream :('))
window = 1
inlet = StreamInlet(streams[0])
info = inlet.info()
descriptions = info.desc()
sfreq = info.nominal_srate()
n_samples = int(window * sfreq)
n_chan = info.channel_count()
print('Acquiring data...')
data = np.zeros((1, n_chan))
times = np.arange(-window, 0, 1./sfreq)
timer = time.time()
end = timer + runTime
while end > timer:
samples, timestamps = inlet.pull_chunk(timeout = 1.0, max_samples = 12)
if timestamps:
timestamps = np.float64(np.arange(len(timestamps))) #creates an array of numbers of numbers from 0 to length timestamps
timestamps /= sfreq #divides that array by our sampling freq
timestamps += times[-1] + 1/sfreq # not sure
times = np.concatenate([times, timestamps])#adds timestamps to the end of the times array
times = times[-n_samples:] #takes the last n_samples from times
data = np.vstack([data, samples]) #adds our new samples to the data array
timer = time.time()
data = np.delete(data, 0, 0) #deletes first column of zeros
return data, sfreq