

@staticmethod
def from_file(filename):
    'Static factory method for reading an EegTrial object from a (gzipped?) file in "eeg_full."\n\n        Keyword arguments:\n        filename -- path plus filename to a UCI EEG database file\n        '
    if filename.endswith('.gz'):
        f = gzip.open(filename, 'r')
    else:
        f = open(filename, 'r')
    l = f.readline()
    m = re.match('# (co\\d(a|c)\\d\\d\\d\\d\\d\\d\\d)', l)
    subject_id = m.group(1)
    alcoholic = (m.group(2) == 'a')
    f.readline()
    f.readline()
    l = f.readline()
    m = re.match('# (.*?), trial (\\d+)', l)
    stimulus = re.sub('\\W', '', m.group(1))
    trial_num = int(m.group(2))
    data = dict()
    o = []
    t = []
    channels = dict()
    curr = None
    for row in csv.reader(f, delimiter=' '):
        if (row[0] == '#'):
            if (curr is not None):
                data[curr] = Series(data=o, index=t)
            o = []
            t = []
            assert (row[1] not in channels)
            channels[row[1]] = int(row[3])
            curr = row[1]
        else:
            assert ((curr is None) or (curr == row[1]))
            t.append(int(row[2]))
            o.append(float(row[3]))
    if (curr is not None):
        data[curr] = Series(data=o, index=t)
    f.close()
    return EegTrial(subject_id=subject_id, alcoholic=alcoholic, trial_num=trial_num, stimulus=stimulus, data=DataFrame(data), channels=Series(channels))

dataset/ETHPy150Open turambar/pyDatasets/pydatasets/uci/eeg.py EegTrial.from_file/original