|
a |
|
b/creating_vector.py |
|
|
1 |
import csv |
|
|
2 |
from collections import defaultdict |
|
|
3 |
import numpy as np |
|
|
4 |
from scipy.signal import * |
|
|
5 |
from numpy.fft import * |
|
|
6 |
from scipy import * |
|
|
7 |
from pylab import * |
|
|
8 |
import pywt |
|
|
9 |
fout_data = open("train.csv",'a') |
|
|
10 |
vec = [] |
|
|
11 |
chan = ['Fp1','AF3','F3','F7','FC5','FC1','C3','T7','CP5','CP1','P3','P7','PO3','O1','Oz','Pz','Fp2','AF4','Fz','F4','F8','FC6','FC2','Cz','C4','T8','CP6','CP2','P4','P8','PO4','O2'] |
|
|
12 |
columns = defaultdict(list) # each value in each column is appended to a list |
|
|
13 |
|
|
|
14 |
with open("features_raw.csv") as f: |
|
|
15 |
reader = csv.DictReader(f) # read rows into a dictionary format |
|
|
16 |
for row in reader: # read a row as {column1: value1, column2: value2,...} |
|
|
17 |
for (k,v) in row.items(): # go over each column name and value |
|
|
18 |
columns[k].append(v) # append the value into the appropriate list |
|
|
19 |
# based on column name k |
|
|
20 |
for i in chan: |
|
|
21 |
x = np.array(columns[i]).astype(np.float) |
|
|
22 |
coeffs = pywt.wavedec(x, 'db4', level=6) |
|
|
23 |
cA6, cD6, cD5,cD4,cD3,cD2,cD1 = coeffs |
|
|
24 |
cD5 = np.std(cD5) |
|
|
25 |
cD4 = np.std(cD4) |
|
|
26 |
cD3 = np.std(cD3) |
|
|
27 |
cD2 = np.std(cD2) |
|
|
28 |
cD1 = np.std(cD1) |
|
|
29 |
if i =="O2": |
|
|
30 |
fout_data.write(str(cD5)+",") |
|
|
31 |
fout_data.write(str(cD4)+",") |
|
|
32 |
fout_data.write(str(cD3)+",") |
|
|
33 |
fout_data.write(str(cD2)+",") |
|
|
34 |
fout_data.write(str(cD1)) |
|
|
35 |
else: |
|
|
36 |
fout_data.write(str(cD5)+",") |
|
|
37 |
fout_data.write(str(cD4)+",") |
|
|
38 |
fout_data.write(str(cD3)+",") |
|
|
39 |
fout_data.write(str(cD2)+",") |
|
|
40 |
fout_data.write(str(cD1)+",") |
|
|
41 |
fout_data.write("\n") |
|
|
42 |
fout_data.close() |