如何在psychopy中从两个单独的块(.xlsx文件)中进行随机选择?

2024-09-28 22:22:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个关于精神病的实验,想随机分两组。我有8个字每个块作为声音刺激(设置1和设置2,这是8x2=16)。目的是给每个参与者提供8个单词,但是来自随机条件(=8个单词,4个来自集合1,4个来自集合2)。刺激集的路径在两个单独的文件中(测试刺激.xlsx和teststimuli2.xlsx)。你知道吗

我用心理变态3.1.5

有两个问题: (1) 刺激以非随机顺序呈现(先是Set1,然后是Set2) (2) 玩了8种刺激后精神病就崩溃了

错误: File “/Users/.../Desktop/.../..._lastrun.py”, line 448, in trialList=data.importConditions(control_blocks.pop(), selection=choice(8, size=4, replace=False)), IndexError: pop from empty list

我已经按照旧版本的psychopy(1.9.5)https://discourse.psychopy.org/t/randomly-selecting-a-subset-of-5-excel-rows-from-groups-of-10-rows-on-each-trial/5098的说明进行了操作。 我试着把$choice(8, size=4, replace=False)改成$choice(7, size=3, replace=False)。以防它从0开始计数。 更糟的是我被困住了。你知道吗

我是python新手,懂一些R,愿意提高!你知道吗

from __future__ import absolute_import, division
from psychopy import locale_setup, sound, gui, visual, core, data, event, logging, clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions
import sys  # to get file system encoding

from psychopy.hardware import keyboard

# Initialize components for Routine "trial_1"
trial_1Clock = core.Clock()
polyTrial1 = visual.Rect(
    win=win, name='polyTrial1',
    width=(2, 2)[0], height=(2, 2)[1],
    ori=0, pos=(0, 0),
    lineWidth=1, lineColor='black', lineColorSpace='rgb',
    fillColor='black', fillColorSpace='rgb',
    opacity=1, depth=0.0, interpolate=True)
text_trial_1 = visual.TextStim(win=win, name='text_trial_1',
    text='\n\n\n   q = oui       p = non\n',
    font='Arial',
    pos=(0, 0), height=0.1, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=-1.0);
sound_trial_1 = sound.Sound('A', secs=-1, stereo=True)
sound_trial_1.setVolume(1.0)
from numpy.random import choice

control_blocks = ['teststimuli.xlsx', 'teststimuli2.xlsx']
shuffle(control_blocks) # randomise order


    # set up handler to look after randomisation of conditions etc
    trial_1_loop = data.TrialHandler(nReps=1, method='random', 
        extraInfo=expInfo, originPath=-1,
        trialList=data.importConditions(control_blocks.pop(), selection=choice(8, size=4, replace=False)),
        seed=None, name='trial_1_loop')
    thisExp.addLoop(trial_1_loop)  # add the loop to the experiment
    thisTrial_1_loop = trial_1_loop.trialList[0]  # so we can initialise stimuli with some values
    # abbreviate parameter names if possible (e.g. rgb = thisTrial_1_loop.rgb)
    if thisTrial_1_loop != None:
        for paramName in thisTrial_1_loop:
            exec('{} = thisTrial_1_loop[paramName]'.format(paramName))

    for thisTrial_1_loop in trial_1_loop:
        currentLoop = trial_1_loop
        # abbreviate parameter names if possible (e.g. rgb = thisTrial_1_loop.rgb)
        if thisTrial_1_loop != None:
            for paramName in thisTrial_1_loop:
                exec('{} = thisTrial_1_loop[paramName]'.format(paramName))

我希望以随机顺序播放8个刺激,分别是Set1的4个和Set2的4个。对于更多的参与者来说,这也是随机的。感谢任何能帮上忙的人!你知道吗


Tags: infromimportnumpyloopdatargbxlsx