Module Expr Str Import alias Import alias Import alias Import alias Import alias Import alias ImportFrom alias alias ClassDef bases body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam defaults ListLoad body Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults Num body Expr Str If CompareGt NameLoad Num body Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpAdd Str NameLoad If CompareGt NameLoad Num body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str orelse Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Assign NameStore Call AttributeLoad NameLoad attr Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr Num Assign NameStore CompareEq Call AttributeLoad NameLoad attr Num Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore ListLoad For NameStore NameLoad body If CompareGt NameLoad Num body Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpAdd BinOpAdd Str NameLoad Str orelse Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str TryExcept body Expr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad handlers ExceptHandler type NameLoad name NameStore body Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpAdd BinOpAdd Str Call NameLoad NameLoad Str orelse If CompareGt NameLoad Num body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Return Call NameLoad keyword NameLoad keyword NameLoad keyword NameLoad decorator_list NameLoad FunctionDef arguments args NameParam NameParam NameParam defaults Str NameLoad body Expr Str If CompareIs NameLoad NameLoad body Assign NameStore Call AttributeLoad Str attr NameLoad Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Call NameLoad NameLoad Str AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call AttributeLoad NameLoad attr Call NameLoad NameLoad Str decorator_list NameLoad FunctionDef arguments args NameParam NameParam defaults Str body Expr Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad AttributeLoad NameLoad attr TryExcept body Expr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler body Pass For NameStore AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr keyword NameLoad decorator_list decorator_list ClassDef bases body Expr Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults body Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Assign AttributeStore NameLoad attr NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr keyword NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr keyword Num keyword NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str If Call AttributeLoad NameLoad attr Str body Assign NameStore Call AttributeLoad NameLoad attr NameLoad Str orelse Assign NameStore Call NameLoad NameLoad Str Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr Num Assign NameStore CompareEq Call AttributeLoad NameLoad attr Num Str Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Str NameLoad Assign NameStore Call AttributeLoad NameLoad attr Str Str Call AttributeLoad NameLoad attr Num Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr Num Assign NameStore Call NameLoad Assign NameStore ListLoad Assign NameStore ListLoad Assign NameStore Call NameLoad Assign NameStore NameLoad For NameStore Call AttributeLoad NameLoad attr NameLoad keyword Str body If CompareEq SubscriptLoad NameLoad Index Num Str body If CompareIsNot NameLoad NameLoad body Assign SubscriptStore NameLoad Index NameLoad Call NameLoad keyword NameLoad keyword NameLoad Assign NameStore ListLoad Assign NameStore ListLoad Assert CompareNotIn SubscriptLoad NameLoad Index Num NameLoad Assign SubscriptStore NameLoad Index SubscriptLoad NameLoad Index Num Call NameLoad SubscriptLoad NameLoad Index Num Assign NameStore SubscriptLoad NameLoad Index Num orelse Assert BoolOpOr CompareIs NameLoad NameLoad CompareEq NameLoad SubscriptLoad NameLoad Index Num Expr Call AttributeLoad NameLoad attr Call NameLoad SubscriptLoad NameLoad Index Num Expr Call AttributeLoad NameLoad attr Call NameLoad SubscriptLoad NameLoad Index Num If CompareIsNot NameLoad NameLoad body Assign SubscriptStore NameLoad Index NameLoad Call NameLoad keyword NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr Return Call NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword Call NameLoad NameLoad keyword Call NameLoad NameLoad decorator_list NameLoad FunctionDef arguments args NameParam defaults body Return Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam defaults body Return ListComp SubscriptLoad AttributeLoad NameLoad attr Index NameLoad comprehension NameStore AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults Str NameLoad body Expr Str If CompareIs NameLoad NameLoad body Assign NameStore Call AttributeLoad Str attr NameLoad IfExp AttributeLoad NameLoad attr Str Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Call NameLoad NameLoad Str AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Return Call AttributeLoad NameLoad attr Call NameLoad NameLoad Str decorator_list NameLoad FunctionDef arguments args NameParam NameParam NameParam defaults Str NameLoad body Expr Str If CompareIs NameLoad NameLoad body Assign NameStore Call AttributeLoad Str attr NameLoad IfExp AttributeLoad NameLoad attr Str Str Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad NameLoad Assign NameStore Call AttributeLoad Call AttributeLoad Call AttributeLoad AttributeLoad NameLoad attr attr keyword AttributeLoad NameLoad attr attr keyword Num attr Expr Call AttributeLoad NameLoad attr BinOpAdd NameLoad Str keyword NameLoad keyword NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpAdd NameLoad Str Assign NameStore Call NameLoad BinOpAdd NameLoad Str Str Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad Expr Call AttributeLoad NameLoad attr decorator_list decorator_list
N/A N/A This module provides classes and utilities for working with the UCI EEG database located at
http://archive.ics.uci.edu/ml/datasets/EEG+Database. There are 122 subjects total in the dataset,
and for each there is multivariate time series data for about 80-120 trials. In each trial the
subject has a 64 channel scalp EEG placed on his head and one second's worth of data (sampled at
256 Hz, i.e., 256 samples/second) is recorded after the subject is shown one of three visual
stimuli. Each trial, then, is a 64 channel by 256 sample time series.

This module assumes you have downloaded and untarred the eeg_full.tar file, which produces a
folder with the following structure:
eeg_full/
    co2a0000364/
        co2a0000364.rd.000.gz
        co2a0000364.rd.002.gz
        co2a0000364.rd.007.gz
        ...
    ...
    co2c0000337/
        co2c0000337.rd.000.gz
        co2c0000337.rd.002.gz
        co2c0000337.rd.016.gz
        ...
    ...

Each subdirectory of eeg_full is a subject, and each gzipped text file is a trial. The second
character in the directory name ("a" or "c") indicates whether the subject is a member of the
alcoholic or control group. Three digits at the end of the trial file name (000-120) indicate
the trial number.

Each trial file has the following structure:

# [filename minus trial number and extension]
# [experimental info (IGNORED)]
# [sampling rate (IGNORED)]
# [stimulus type] , [trial #]
# [channel name] chan [channel number]
[channel number] [channel name] [timestamp] measurement
[channel number] [channel name] [timestamp] measurement
[channel number] [channel name] [timestamp] measurement
...
# [channel name] chan [channel number]
[channel number] [channel name] [timestamp] measurement
[channel number] [channel name] [timestamp] measurement
[channel number] [channel name] [timestamp] measurement
...

An example being:

# co2a0000364.rd
# 120 trials, 64 chans, 416 samples 368 post_stim samples
# 3.906000 msecs uV
# S1 obj , trial 0
# FP1 chan 0
0 FP1 0 -8.921
0 FP1 1 -8.433
0 FP1 2 -2.574
...
# FP2 chan 1
0 FP2 0 0.834
0 FP2 1 3.276
0 FP2 2 5.717
...
 N/A csv N/A gzip N/A os N/A pickle N/A re N/A sys pandas DataFrame Series EegSubject N/A N/A N/A Reads, parses, prepares, and stores data for one subject.

    Keyword arguments:
    subject_id  -- subject id (e.g., 'co2a0000364')
    alcoholic   -- boolean, whether subject is alcoholic
    trials_data -- list of trials data (could be list of EegTrial objects)
     __init__ N/A N/A self subject_id alcoholic trials_data N/A N/A N/A N/A N/A self subject_id N/A str subject_id N/A N/A self alcoholic N/A bool alcoholic N/A N/A self trials_data trials_data N/A from_directory N/A N/A path verbosity N/A 1 N/A N/A Static factory method for reading an EegSubject object from a subdirectory of "eeg_full."

        Keyword arguments:
        path -- path to a UCI EEG database subject folder
        verbosity -- level of verbosity
         N/A N/A verbosity 0 N/A N/A N/A N/A N/A sys stdout write N/A Reading EegSubject from directory  path N/A N/A verbosity 1 N/A N/A N/A N/A N/A sys stdout write N/A N/A N/A N/A N/A sys stdout write : N/A m N/A N/A re match .*/?(co\d(a|c)\d\d\d\d\d\d\d) path N/A subject_id N/A N/A m group 1 N/A alcoholic N/A N/A N/A m group 2 a N/A filenames N/A N/A os listdir path N/A trials_data N/A N/A filename filenames N/A N/A N/A verbosity 1 N/A N/A N/A N/A N/A sys stdout write N/A N/A   reading EegTrial from  filename ... N/A N/A N/A N/A N/A sys stdout write . N/A N/A N/A N/A N/A trials_data append N/A N/A EegTrial from_file N/A N/A N/A os path join path filename N/A N/A N/A Exception N/A e N/A N/A N/A N/A N/A sys stdout write N/A N/A ERROR: could not read EegTrial from file:  N/A str e N/A N/A N/A verbosity 1 N/A N/A N/A N/A N/A sys stdout write SUCCESS
 N/A N/A N/A N/A sys stdout write N/A N/A EegSubject subject_id subject_id alcoholic alcoholic trials_data trials_data N/A staticmethod to_pickle N/A N/A self path filename N/A None N/A N/A Pickle (serialize) EegSubject object to disk.

        Keyword arguments:
        path -- path without filename to store pickled object
        filename -- filename to append to path, optional
         N/A N/A filename None N/A N/A filename N/A N/A {0.subject_id}.pkl format self N/A filename N/A N/A N/A os path join path filename N/A N/A N/A pickle dump self N/A open filename w N/A pickle HIGHEST_PROTOCOL N/A from_pickle N/A N/A filename N/A N/A N/A Read EegSubject object from pickle file. N/A N/A N/A pickle load N/A open filename r N/A staticmethod to_csvs N/A N/A self path N/A N/A N/A Store EegSubject to disk as CSVs, one trial per CSV, in a directory.

        Keyword arguments:
        path -- directory to store CSVs
         N/A subdir N/A N/A N/A os path join path N/A self subject_id N/A N/A N/A N/A N/A os makedirs subdir N/A N/A N/A N/A N/A trial N/A self trials_data N/A N/A N/A N/A trial to_csv path subdir N/A N/A EegTrial N/A N/A N/A Reads, parses, prepares, and stores data for one trial.

    Keyword arguments:
    subject_id  -- subject id (e.g., 'co2a0000364')
    alcoholic   -- boolean, whether subject is alcoholic
    trial_num   -- trial number, 000-120
    stimulus    -- type of stimulus (raw string is fine)
    data        -- measurements data
    trials_data -- dictionary mapping channel name to channel number

    Notes:
    Will attempt to coerce "data" into a pandas.DataFrame so you should pass
    in something that is compatible (just pass a DataFrame!). Probably "channels"
    should be a plain dictionary with channel name as key, channel number as value.
    This is overkill: the channels appeared to be numbered consistently throughout
    the UCI EEG data set, but it's good practice: they don't HAVE to be numbered
    consistently...
     __init__ N/A N/A self subject_id alcoholic trial_num stimulus data channels N/A N/A N/A N/A self subject_id N/A str subject_id N/A N/A self alcoholic N/A bool alcoholic N/A N/A self trial_num N/A int trial_num N/A N/A self stimulus N/A str stimulus N/A N/A self data N/A DataFrame data N/A N/A self channels channels N/A N/A N/A N/A self data sort_index inplace True N/A N/A N/A N/A self data sort axis 1 inplace True N/A from_file N/A N/A filename N/A N/A N/A Static factory method for reading an EegTrial object from a (gzipped?) file in "eeg_full."

        Keyword arguments:
        filename -- path plus filename to a UCI EEG database file
         N/A N/A N/A filename endswith .gz N/A N/A f N/A N/A gzip open filename r N/A N/A f N/A open filename r N/A l N/A N/A f readline N/A m N/A N/A re match # (co\d(a|c)\d\d\d\d\d\d\d) l N/A subject_id N/A N/A m group 1 N/A alcoholic N/A N/A N/A m group 2 a N/A N/A N/A f readline N/A N/A N/A f readline N/A l N/A N/A f readline N/A m N/A N/A re match # (.*?), trial (\d+) l N/A stimulus N/A N/A re sub \W N/A N/A m group 1 N/A trial_num N/A int N/A N/A m group 2 N/A data N/A dict N/A o N/A N/A t N/A N/A channels N/A dict N/A curr None N/A row N/A N/A csv reader f delimiter N/A N/A N/A N/A row N/A 0 # N/A N/A N/A curr None N/A N/A N/A data N/A curr N/A Series data o index t N/A o N/A N/A t N/A N/A N/A N/A row N/A 1 channels N/A N/A channels N/A N/A row N/A 1 N/A int N/A row N/A 3 N/A curr N/A row N/A 1 N/A N/A N/A N/A curr None N/A curr N/A row N/A 1 N/A N/A N/A t append N/A int N/A row N/A 2 N/A N/A N/A o append N/A float N/A row N/A 3 N/A N/A curr None N/A N/A N/A data N/A curr N/A Series data o index t N/A N/A N/A f close N/A N/A EegTrial subject_id subject_id alcoholic alcoholic trial_num trial_num stimulus stimulus data N/A DataFrame data channels N/A Series channels N/A staticmethod get_channel_names N/A N/A self N/A N/A N/A N/A list N/A N/A self data columns N/A get_channel_numbers N/A N/A self N/A N/A N/A N/A N/A N/A self channels N/A c N/A c N/A N/A self data columns N/A as_nparray N/A N/A self N/A N/A N/A Spits out data as a D x T numpy.array (D=# channels, T=# samples)

        Notes:
        Notice what we do here: we start with a pandas.DataFrame where each channel
        is a column (so you can think of it as a T x D matrix). We first rename the
        columns to channel numbers,then sort the columns, then sort the index, then
        transform to numpy.array, then finally take the transpose to get T x D.
         N/A N/A N/A N/A self data as_matrix N/A to_pickle N/A N/A self path filename N/A None N/A N/A Pickle (serialize) EegTrial object to disk.

        Keyword arguments:
        path -- path without filename to store pickled object
        filename -- filename to append to path, optional
         N/A N/A filename None N/A N/A filename N/A N/A {0.subject_id}-{1}-{0.trial_num:03}-{0.stimulus}.pkl format self N/A N/A self alcoholic a c N/A filename N/A N/A N/A os path join path filename N/A N/A N/A pickle dump self N/A open filename w N/A pickle HIGHEST_PROTOCOL N/A from_pickle N/A N/A filename N/A N/A N/A Read EegTrial object from pickle file. N/A N/A N/A pickle load N/A open filename r N/A staticmethod to_csv N/A N/A self path filename_base N/A None N/A N/A Store EegTrial to disk as three CSVs: data, channel dictionary, info.

        Keyword arguments:
        path -- directory to store CSVs
        filename_base -- base of filename (extensions will be appended)
         N/A N/A filename_base None N/A N/A filename_base N/A N/A {0.subject_id}-{1}-{0.trial_num:03}-{0.stimulus} format self N/A N/A self alcoholic a c N/A filename_base N/A N/A N/A os path join path filename_base N/A temp N/A N/A N/A N/A N/A N/A N/A self data rename columns N/A self channels sort axis 1 sort_index N/A N/A N/A temp to_csv N/A filename_base .data header False index False N/A N/A N/A N/A self channels to_csv N/A filename_base .channels N/A f N/A open N/A filename_base .info w N/A N/A N/A f write N/A N/A subject_id,{0.subject_id}
alcoholic,{0.alcoholic}
trial_num,{0.trial_num}
stimulus,{0.stimulus} format self N/A N/A N/A f close N/A N/A