In [1]:
%matplotlib inline
In [13]:
import numpy as np, pandas as pd
import matplotlib.pyplot as plt
from scipy import signal
import os
import re
from datetime import datetime
import pytz
from tabulate import tabulate
In [271]:
path_resp = '/home/mike/w/bci_erp/python/sampleData/run9/oddball_run_2017-02-05_15-02-45.csv'
# path_2 = '/home/mike/w/bci_erp/python/sampleData/oddball_run_2017-02-04_13-02-08.txt'
resp = pd.read_csv(path_resp)
# resp.columns = ['time', 'unixtime', 'resp', 'tone', 'ecode', 'label']
resp['unixtime'] = pd.to_numeric(resp['unixtime'])
resp.head()
Out[271]:
In [272]:
# pd.to_datetime(resp['unixtime']/1000, unit='s')
In [273]:
path_bci = '/home/mike/w/bci_erp/python/sampleData/run9/OpenBCI-RAW-ob_2017-02-05_15-00-49.txt'
bci = pd.read_csv(path_bci, sep=', ', skiprows=6, header=None)
chan_columns = [str(i) for i in range(1,9)]
bci.columns = ['ticks'] + chan_columns + ['a', 'b', 'c', 'unixtime']
bci['unixtime'] = pd.to_numeric(bci['unixtime'])
bci.head()
Out[273]:
watch out for stupid windows backslashes
In [3]:
example_header = r"""
# Non-editable header begin --------------------------------------------------------------------------------
#
# data format...............: continuous
# setname...................: S1_EEG_elist
# filename..................: S1_EEG.set
# filepath..................: C:\Users\mike\Downloads\Test_Data\Test_Data\S1\
# nchan.....................: 16
# pnts......................: 1069520
# srate.....................: 500
# nevents...................: 2557
# generated by (bdf)........:
# generated by (set)........: S1_EEG_elist
# reported in ..............:
# prog Version..............: 6.1
# creation date.............: 03-Feb-2017 10:51:12
# user Account..............:
#
# Non-editable header end --------------------------------------------------------------------------------
# item bepoch ecode label onset diff dura b_flags a_flags enable bin
# (sec) (msec) (msec) (binary) (binary)
"""
In [10]:
header_meta = '''
# Non-editable header begin --------------------------------------------------------------------------------
#
# data format...............: {dataFormat}
# setname...................: {setname}
# filename..................: {filename}
# filepath..................: {filepath}
# nchan.....................: {nchan}
# pnts......................: {pnts}
# srate.....................: {srate}
# nevents...................: {nevents}
# generated by (bdf)........: python
# generated by (set)........: python
# reported in ..............:
# prog Version..............: 6.1
# creation date.............: {createdDate}
# user Account..............: {user}
#
# Non-editable header end --------------------------------------------------------------------------------
'''
In [11]:
header_cols = """
# item bepoch ecode label onset diff dura b_flags a_flags enable bin
# (sec) (msec) (msec) (binary) (binary)
"""
In [12]:
print(header_meta + header_cols)
Format is fixed-width
item = (int) ordinal index, starts with 1
bepoch = (int) ?bin epoch? typically 0
ecode = (uint8) numerical code [0-255] which codes for type of event (aka type)
label = (str) given label, empty is ""
onset = (float) time from start to event (seconds) aka latency
diff = (float) time since prior event (millis)
dura = (bin8) no idea, default=00000000
b_flags = (bin8) bin flags, default=00000000
a_flags = (bin8) artefact flags, default=00000000
enable = (bit) 1/0 for true/false
bin = (list) List of bin numbers, empty is [ ] (7 spaces)
In [14]:
eventlist_name = '/media/mike/tera/data/erplab/Test_Data/S1/event_export02.txt'
In [37]:
eventlist_df = pd.read_fwf(eventlist_name, skiprows=28, header=None)
In [38]:
eventlist_df.head()
Out[38]:
In [42]:
# well, that failed, because it's formatted horribly
with open(eventlist_name, 'r') as infile:
eventlist_raw = infile.readlines()
In [46]:
data = eventlist_raw[26:]
In [47]:
data[0]
Out[47]:
In [48]:
re_inquotes = '\"([\w _\./\\-]*)\"'
In [ ]: