In [1]:
from eegml import *
print_config()

try: # Import config params
   from dev_settings import *
except ImportError:
   print "Please create a dev_settings.py using dev_settings.py.example as an example"


/home/justis/student/csc591/eeg_all
preprocess

Format task.xls

machine subject start_time end_time stim block poolmodality text difficult

A typical row in task.xls:

['a', 'a', '2010-12-14 17:05:40.883', '2010-12-14 17:05:43.852', 'A tree is a plant. ', 'A tree is a plant. A tree is the biggest plant that grows. Most kinds of trees grow from seeds the way most small plants do. There are many kinds of trees. Here are a few of them. How many do you know? This tree grows in the country. It might grow in your yard, too. Do you know what kind it is? This is an apple tree. ', '1', '2', '1', '1']

Generate

  • task_xls_labels.csv

In [2]:
format_task_xls()

Generate compreseed file [deprecated]

  • task_xls_labels_compress.csv

In [3]:
compress_time_labels("./preprocess/task_xls_labels.csv")

Find out the Subject IDs and Time of experiment


In [4]:
from os import listdir
from os.path import isfile, join
import re

onlyfiles = [ f for f in listdir(DATA_URL) if isfile(join(DATA_URL,f)) ]
pat = re.compile("[0-9]*\.[0-9]*\.combined\.csv")
temp_dat = [f.split('.')[0:2] for f in onlyfiles if pat.match(f)]
sub_dict = {i[1]: i[0] for i in temp_dat}

Label 1Hz data

file:"../data/eeg_sample/20101214163931.a.combined.csv"


In [5]:
for i in sub_dict:
    label_data(DATA_URL + "/"+sub_dict[i] + "." +i+".combined.csv",
            SAVE_URL + "/task_xls_labels.csv",
            SAVE_URL + "/"+sub_dict[i] + "." +i+".labelled.csv",
            i, sub_dict[i])

Label 512 Hz data


In [7]:
create_raw_incremental(DATA_URL + "/20101214163931.a.rawwave.csv", "preprocess/raw_incremental.csv")
label_data_raw_signal("preprocess/raw_incremental.csv",
            "preprocess/task_xls_labels.csv",
            "preprocess/raw_incremental_label.csv")


---------------------------------------------------------------------------
InvalidOperation                          Traceback (most recent call last)
<ipython-input-7-ec9eb20b7b9b> in <module>()
      1 label_data_raw_signal("preprocess/raw_incremental.csv",
      2             "preprocess/task_xls_labels.csv",
----> 3             "preprocess/raw_incremental_label.csv")

/home/justis/src/edm_eeg/eegml.py in label_data_raw_signal(in_file, compressed_label_file, out_file)
    145             row[0] = datetime.strptime(day+' '+row[0],\
    146                             '%Y-%m-%d %H:%M:%S.%f').strftime('%s.%f')
--> 147             if Decimal(row[0]) < Decimal(lab_row[1]): # t < start_time
    148                 label = -1
    149                 fw.writerow(row + [label, lab_row[0]])

/usr/lib/python2.7/decimal.pyc in __new__(cls, value, context)
    546                     context = getcontext()
    547                 return context._raise_error(ConversionSyntax,
--> 548                                 "Invalid literal for Decimal: %r" % value)
    549 
    550             if m.group('sign') == "-":

/usr/lib/python2.7/decimal.pyc in _raise_error(self, condition, explanation, *args)
   3864         # Errors should only be risked on copies of the context
   3865         # self._ignored_flags = []
-> 3866         raise error(explanation)
   3867 
   3868     def _ignore_all_flags(self):

InvalidOperation: Invalid literal for Decimal: 'a'

Plot raw data


In [11]:
with open("preprocess/raw_incremental_label.csv", 'rb') as fi:
    fr = csv.reader(fi, delimiter='\t')
    next(fr)
    a = list(fr)
    
    fig, ax = plt.subplots()
    x_ax = [int(i[0].split('.')[0]) for i in a]
    
    diffi = [int(i[2]) for i in a]
    
    #print x_ax
    #ax.plot(x_ax,sig_q, label='Quality')
    #ax.plot(x_ax,atten, label='Attention')
    #ax.plot(x_ax,medit, label='Meditation')
    ax.plot(x_ax,diffi, label='Difficulty')
    
    ax.grid(True)
    fig.tight_layout()
    plt.legend(loc='upper left')
    plt.show()