Пример #1
0
def join_data():
    from expyriment.misc import data_preprocessing
    print "Joining data"
    sys.stdout.write(" data subfolder [optional, default=data]? ")
    folder = raw_input()
    if len(folder) <= 0:
        folder = "data"
    start_with = raw_input(" data files start with [optional]? ")
    d = data_preprocessing.Aggregator(folder, start_with)
    return d
Пример #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Example analysis script for snarc_experiment.py

The current script produces two files for different analysis of the SNARC
effect (ANOVA vs. slopes analysis) using mean and median RTs

"""

from expyriment.misc import data_preprocessing, constants


agg = data_preprocessing.Aggregator(data_folder="./data/",
                                    file_name="snarc_experiment")

agg.set_subject_variables(["mapping_order"])
agg.set_computed_variables(["parity = digit % 2", #0:odd, 1:even
                      "size = digit > 5", #0:small, 1:large
                      "space = btn == {0}".format(constants.K_RIGHT) #0:left, 1:right
                      ])
# RTs: space x size
agg.set_exclusions(["RT > 1000", "RT < 200", "error == 1", "trial<0"])
agg.set_dependent_variables(["mean(RT)"])
agg.set_independent_variables(["size", "space"])
print agg
agg.aggregate(output_file="rt_size_space.csv")
# RTs: slopes analysis
agg.set_independent_variables(["digit"])
agg.aggregate(output_file="rt_digits.csv")
Пример #3
0
def import_one_subject(rootdir, file_name):
    """
    Import the data of one subject, and do some basic preprocessing
    """

    # Load data file
    agg = data_preprocessing.Aggregator(data_folder=rootdir,
                                        file_name=file_name)

    # ignore lines that correspond to the register of >2 presses per trial
    trial = agg.get_variable_data("TrialId").flatten()
    n = len(trial)
    ignore = []
    for line in range(n):
        if line > 0:
            if trial[line] == trial[line - 1]:
                ignore.append(1)
            else:
                ignore.append(0)
        else:
            ignore.append(0)
    ignore = np.array(ignore)
    trial = np.array(list(map(int, trial)))[ignore == 0]

    multi_press = agg.get_variable_data("IsMultiKeyPress").flatten()
    multi_press = np.array([
        0 if e == 'False' else (1 if e == 'True' else -1) for e in multi_press
    ])
    multi_press = multi_press[ignore == 0]

    RT = agg.get_variable_data("RT").flatten()
    RT = np.array([int(rt) if rt != 'None' else -1
                   for rt in RT]).astype('int64')
    RT = RT[ignore == 0]

    Correct = agg.get_variable_data("Correct").flatten()
    Correct = np.array([1 if c == 'True' else 0 for c in Correct])
    Correct = Correct[ignore == 0]

    onset = agg.get_variable_data("StimulusOnset").flatten()
    onset = onset[ignore == 0]

    block = agg.get_variable_data("BlockId").flatten()
    block = np.array(list(map(int, block)))[ignore == 0]

    seq = agg.get_variable_data("Stimulus").flatten()
    seq = np.array([1 if stim == 'True' else 0 for stim in seq])
    seq = seq[ignore == 0]

    serie = agg.get_variable_data("SerieId").flatten()
    serie = np.array(list(map(int, serie)))[ignore == 0]

    motor = agg.get_variable_data("Motricity").flatten()
    motor = np.array(list(map(int, motor)))[ignore == 0]

    ecc = agg.get_variable_data("Eccentricity").flatten().astype('int64')
    ecc = np.array(list(map(int, ecc)))[ignore == 0]

    delay = agg.get_variable_data("Delay").flatten()
    delay = np.array(list(map(int, delay)))[ignore == 0]

    rep = agg.get_variable_data("Repetition").flatten()
    rep = np.array([1 if r == 'True' else 0 for r in rep])
    rep = rep[ignore == 0]

    return {
        "trial": trial,
        "multi_press": multi_press,
        "RT": RT,
        "Correct": Correct,
        "onset": onset,
        "block": block,
        "seq": seq,
        "serie": serie,
        "motor": motor,
        "ecc": ecc,
        "delay": delay,
        "rep": rep
    }
Пример #4
0
def extractRecognitionAnswers(iFolder, iFile):
    #
    #
    #
    agg = data_preprocessing.Aggregator(data_folder=iFolder, file_name=iFile)
    header = data_preprocessing.read_datafile(
        iFolder + iFile, only_header_and_variable_names=True)
    header = header[3].split('\n#e ')

    pOrder = header[header.index('Presentation Order:') +
                    1:header.index('Presentation Order:') + 6]
    pOrder = ''.join(pOrder)
    non_decimal = re.compile(r'[^\d.]+')
    pOrder = non_decimal.sub('', pOrder)
    pOrder = pOrder.split('.')
    pOrder = [int(x) for x in pOrder[0:-1]]

    matrixA = ast.literal_eval(header[header.index('Learning:') +
                                      1].split('\n')[0].split('\n')[0])

    data = {}
    for variable in agg.variables:
        data[variable] = agg.get_variable_data(variable)

    validCards = correctCards()
    inValidCards = wrongCards()

    aCorrect = np.logical_and(data['Matrix'] == 'MatrixA',
                              data['CorrectAnswer'] == 'True')
    aNotCorrect = np.logical_and(data['Matrix'] == 'MatrixA',
                                 data['CorrectAnswer'] == 'False')

    rndCorrect = np.logical_and(data['Matrix'] == 'MatrixRandom',
                                data['CorrectAnswer'] == 'True')
    rndNotCorrect = np.logical_and(data['Matrix'] == 'MatrixRandom',
                                   data['CorrectAnswer'] == 'False')

    for idx, val in enumerate(aCorrect):
        if val[0]:
            validCards.name.append(matrixA[pOrder[idx]])
            validCards.position.append(pOrder[idx])

    for idx, val in enumerate(aNotCorrect):
        if val[0]:
            inValidCards.name.append(matrixA[pOrder[idx]])
            inValidCards.position.append(pOrder[idx])

    validCards.animals = [word for word in validCards.name if word[0] == 'a']
    validCards.clothes = [word for word in validCards.name if word[0] == 'c']
    validCards.vehicules = [word for word in validCards.name if word[0] == 'v']
    validCards.fruits = [word for word in validCards.name if word[0] == 'f']

    inValidCards.animals = [
        word for word in inValidCards.name if word[0] == 'a'
    ]
    inValidCards.clothes = [
        word for word in inValidCards.name if word[0] == 'c'
    ]
    inValidCards.vehicules = [
        word for word in inValidCards.name if word[0] == 'v'
    ]
    inValidCards.fruits = [
        word for word in inValidCards.name if word[0] == 'f'
    ]

    return data, validCards, inValidCards, matrixA
Пример #5
0
def extractCorrectAnswers(iFolder, iFile):
    #
    #
    #
    agg = data_preprocessing.Aggregator(data_folder=iFolder, file_name=iFile)
    header = data_preprocessing.read_datafile(
        iFolder + iFile, only_header_and_variable_names=True)
    header = header[3].split('\n#e ')
    data = {}
    for variable in agg.variables:
        data[variable] = agg.get_variable_data(variable)

    validCards = correctCards()
    inValidCards = wrongCards()

    indexBlocks = np.unique(data['NBlock'])

    for block in indexBlocks:
        correctAnswers = np.logical_and(data['Picture'] == data['Answers'],
                                        data['NBlock'] == block)
        wrongAnswers = np.logical_and(data['Picture'] != data['Answers'],
                                      data['NBlock'] == block)

    matrixPictures = ast.literal_eval(
        header[header.index('Positions pictures:') +
               1].split('\n')[0].split('\n')[0])

    for idx, val in enumerate(correctAnswers):
        if val:
            validCards.name.append(data['Answers'][idx][0])
            validCards.position.append(
                matrixPictures.index(data['Answers'][idx]))

    validCards.animals = [word for word in validCards.name if word[0] == 'a']
    validCards.clothes = [word for word in validCards.name if word[0] == 'c']
    validCards.vehicules = [word for word in validCards.name if word[0] == 'v']
    validCards.fruits = [word for word in validCards.name if word[0] == 'f']

    for idx, val in enumerate(wrongAnswers):
        if val:
            inValidCards.name.append(data['Answers'][idx][0])
            inValidCards.picture.append(data['Picture'][idx][0])
            if 'None' in data['Answers'][idx][0]:
                inValidCards.position.append(100)
            else:
                inValidCards.position.append(
                    matrixPictures.index(data['Answers'][idx]))

    inValidCards.animals = [
        word for word in inValidCards.name if word[0] == 'a'
    ]
    inValidCards.clothes = [
        word for word in inValidCards.name if word[0] == 'c'
    ]
    inValidCards.vehicules = [
        word for word in inValidCards.name if word[0] == 'v'
    ]
    inValidCards.fruits = [
        word for word in inValidCards.name if word[0] == 'f'
    ]

    return data, validCards, inValidCards, matrixPictures
Пример #6
0
import sys

from config import dataFolder
from expyriment.misc import data_preprocessing
import numpy as np

agg = data_preprocessing.Aggregator(data_folder=dataFolder,
                                    file_name=sys.argv[1])

print 'Variable computed: '
data = {}
for variable in agg.variables:
    data[variable] = agg.get_variable_data(variable)

indexBlocks = np.unique(data['NBlock'])

for block in indexBlocks:
    print 'Block {}'.format(block)
    correctAnswers = np.logical_and(data['Picture']==data['Answers'], data['NBlock']==block)
    wrongAnswers = np.logical_and(data['Picture']!=data['Answers'], data['NBlock']==block)
    correctRT = [int(i) for i in data['RT'][correctAnswers]]
    print 'Correct answers: {}'.format(len(correctRT))
    print 'Mean correct RT: {} ms'.format(np.mean(correctRT))