Exemple #1
0
  % Sensitive to identical keys in all trial-dicts
"""

# Generate trial list
trials = [{
    'opacity': opacity,
    'image': image,
    'answer': '',
    'score': ''
} for opacity in opacities for image in images for rep in range(reps)]
trials = random.sample(trials, len(trials))
for i, trial in enumerate(trials):
    trial['no'] = i + 1  # randomize and add trial numbers

# Update trials and save
writer = csvWriter('results_manual', '', trials[0])
for trial in trials:
    trial['answer'] = random.choice(['left', 'right'])
    trial['score'] = random.randint(0, 1)
    writer.write(trial)
"""
3. PANDAS VERSION
  + Great for analysis of cross-trial data
  % Too complex. Rather do the manual version and convert trials to DataFrame when you need to process data
"""

# Generate trial list
trials = [{
    'opacity': opacity,
    'image': image,
    'answer': '',
Exemple #2
0

def rate_media():
    full_txt = "How many hours per week do you spend following the news?"
    msg = visual.TextStim(win, text=full_txt, pos=(0, 0.1))

    media_rating.reset()
    while media_rating.noResponse:
        media_rating.draw()
        msg.draw()
        win.flip()
    return (media_rating.getRating())


writer = ppc.csvWriter(ID,
                       saveFolder="data",
                       headerTrial=person_stories_trials[1])

####unite dataframes to df
for i in intro:
    show_info(i)

if k == 0:
    person_stories_function()
    topic_function()
else:
    topic_function()
    person_stories_function()

news_rating = {
    'ID': ID,
Exemple #3
0
REPETITIONS = 4  # 3 reps* 4 different setsizes * 2 (presence) * 4 (conjunction) = 128 trials
condition = 'visual_search'  #Just a variable. If the script can run several exp. then this can be called in GUI. Not relevant here.
""" OUTPUT """

#KEYS
KEYS_present = ['t']  #T is response key for target present.
KEYS_absent = [
    'y', 'r'
]  #Y and R (present next to T) are response key for target absent. One can be used for righthanders, the other for lefthanders

#response keys for quitting and starting
KEYS_QUIT = ['escape']  # Keys that quits the experiment
KEYS_start = ['space']  # press space to start
# Prepare a csv log-file using the ppc script
writer = ppc.csvWriter(
    str(V['ID']), saveFolder=SAVE_FOLDER
)  # writer.write(trial) will write individual trials with low latency
""" FUNCTIONS FOR EXPERIMENTAL LOOP"""


#Generate a trial list with different combinations of the experimental factors
def make_trial_list(condition):
    # Factorial design
    trial_list = []
    for rowsize in rowsizes:  # number of letters in stim rows
        for conjunct in conjunction:
            for present in presence:
                for rep in range(REPETITIONS):
                    # Add a dictionary for every trial
                    trial_list += [{
                        'ID': V['ID'],
Exemple #4
0
# Create psychopy window
my_monitor = monitors.Monitor(
    'testMonitor'
)  # Create monitor object from the variables above. This is needed to control size of stimuli in degrees.
win = visual.Window(
    monitor=my_monitor,
    size=MON_SIZE,
    color=[-1, -1, -1],
    units='deg',
    fullscr=True,
    allowGUI=False
)  # Initiate psychopy Window as the object "win", using the myMon object from last line. Use degree as units!

# Stuff
clock = core.Clock()
writer = ppc.csvWriter(str(V['subject']), saveFolder=SAVE_FOLDER)

# create base stimli

square1 = visual.Rect(win, width=2, height=2, pos=([-5, 0]))
square2 = visual.Rect(win, width=2, height=2, pos=([0, 0]))
square3 = visual.Rect(win, width=2, height=2, pos=([5, 0]))
fixation = visual.TextStim(win, text='+', pos=([0, .05]),
                           height=1)  # check sizes, should be 1x1 degrees

# Responses and keys
KEYS_QUIT = ['q']  # Keys that quits the experiment
RESPONSES = {'left': 'lctrl', 'right': 'rctrl'}
RESP_POS = {'lctrl': 'X', 'rctrl': 'O'}

# Create stimuli
"""
2. GENERIC PYTHON VERSION
  + good control
  + pure core python (occam's razor)
  % Sensitive to identical keys in all trial-dicts
"""

# Generate trial list
trials = [{'opacity': opacity, 'image': image, 'answer':'', 'score':''}
    for opacity in opacities for image in images for rep in range(reps)]
trials = random.sample(trials, len(trials))
for i, trial in enumerate(trials):
    trial['no'] = i + 1  # randomize and add trial numbers

# Update trials and save
writer = csvWriter('results_manual', '', trials[0])
for trial in trials:
    trial['answer'] = random.choice(['left', 'right'])
    trial['score'] = random.randint(0,1)
    writer.write(trial)


"""
3. PANDAS VERSION
  + Great for analysis of cross-trial data
  % Too complex. Rather do the manual version and convert trials to DataFrame when you need to process data
"""

# Generate trial list
trials = [{'opacity': opacity, 'image': image, 'answer':'', 'score':''}
    for opacity in opacities for image in images for rep in range(reps)]
import ppc
print 'the physical diameter of the gabor patch should be', ppc.deg2cm(GABOR_SIZE, MON_DISTANCE), 'cm'
print 'the physical size of the fixation cross should be', ppc.deg2cm(FIX_HEIGHT, MON_DISTANCE), 'cm'

from psychopy import core, visual, gui, monitors, sound, event
import random

# Intro-dialogue. Get subject-id and other variables.
# Save input variables in "V" dictionary (V for "variables")
V = {'subject':'', 'condition': ['trueFix', 'falseFix'], 'age':'', 'gender':['male', 'female']}
if not gui.DlgFromDict(V, order=['subject', 'age', 'gender']).OK:
    core.quit()

# Stuff
clock = core.Clock()  # A clock wich will be used throughout the experiment to time events on a trial-per-trial basis (stimuli and reaction times).
writer = ppc.csvWriter(str(V['subject']), saveFolder=SAVE_FOLDER)  # writer.write(trial) will write individual trials with low latency

# Create psychopy window
my_monitor = monitors.Monitor('testMonitor', width=MON_WIDTH, distance=MON_DISTANCE)  # Create monitor object from the variables above. This is needed to control size of stimuli in degrees.
my_monitor.setSizePix(MON_SIZE)
win = visual.Window(monitor=my_monitor, units='deg', fullscr=True, allowGUI=False, color='black')  # Initiate psychopy Window as the object "win", using the myMon object from last line. Use degree as units!

# Stimuli.
stim_gabor = visual.GratingStim(win, mask='gauss', sf=GABOR_SF, size=GABOR_SIZE)  # A gabor patch. Again, units are inherited.
stim_fix = visual.TextStim(win, '+', height=FIX_HEIGHT)  # Fixation cross is just the character "+". Units are inherited from Window when not explicitly specified.
stim_text = visual.TextStim(win, pos=MESSAGE_POS, height=MESSAGE_HEIGHT, wrapWidth=999)  # Message / question stimulus. Will be used to display instructions and questions.
sound_success = sound.Sound('C', secs=0.1, octave=6)  # Obs, ppc.Sound() is much more accurate, but only works on windows.
sound_fail = sound.Sound('C', secs=0.4, octave=4)


"""
  % Sensitive to identical keys in all trial-dicts
"""

# Generate trial list
trials = [
    {"opacity": opacity, "image": image, "answer": "", "score": ""}
    for opacity in opacities
    for image in images
    for rep in range(reps)
]
trials = random.sample(trials, len(trials))
for i, trial in enumerate(trials):
    trial["no"] = i + 1  # randomize and add trial numbers

# Update trials and save
writer = csvWriter("results_manual", "", trials[0])
for trial in trials:
    trial["answer"] = random.choice(["left", "right"])
    trial["score"] = random.randint(0, 1)
    writer.write(trial)


"""
3. PANDAS VERSION
  + Great for analysis of cross-trial data
  % Too complex. Rather do the manual version and convert trials to DataFrame when you need to process data
"""

# Generate trial list
trials = [
    {"opacity": opacity, "image": image, "answer": "", "score": ""}