Errors when trying to randomize images from both condition file and code snippet

OS : Windows 10 64-bit
PsychoPy version : PsychoPy v2020.1.3
Standard Standalone? : (y)

What are you trying to achieve?: I am using builder + code to create a task where participants have to locate a target shape (either a square or diamond) among 0-5 other non-target shapes, in 6 fixed positions. They also have to ignore a potential distractor shape that appears on the left or right side of the display (4 levels: square, diamond, triangle, or blank image, i.e., no distractor appears).

The target and non-targets can randomly appear in any of the 6 fixed positions but without overlapping (e.g., target appears in position 1, so non-targets appear in position 2-6), and 0 to 5 non-targets should randomly appear from trial-to-trial.

What did you try to make it work?:
In my conditions file, I created 8 types of trials, from combining 2 target shapes x 4 distractors. This is where I specified the image path files for these 6 images. The only things I specified were image paths (“targetShape”, “distShape”) and the correct key response (“corrAns”).

In builder, I added image components for a target, distractor, and 5 non-targets.

In the code under Begin Experiment, I defined the non-target image path files (plus a blank image):

# define ntargs images
n_hex ='C:/Users/ronda/Google Drive/grad/projects/11 new PL study/python ver/stim/ntarg/hex.png'
n_penta1 ='C:/Users/ronda/Google Drive/grad/projects/11 new PL study/python ver/stim/ntarg/penta1.png'
n_penta2 ='C:/Users/ronda/Google Drive/grad/projects/11 new PL study/python ver/stim/ntarg/penta2.png'
n_tri1 ='C:/Users/ronda/Google Drive/grad/projects/11 new PL study/python ver/stim/ntarg/tri1.png'
n_tri2 ='C:/Users/ronda/Google Drive/grad/projects/11 new PL study/python ver/stim/ntarg/tri2.png'
blank = 'C:/Users/ronda/Google Drive/grad/projects/11 new PL study/builder and code ver/stim/blank.png'

And I also created lists for non-target images, distractor positions, target/non-target positions, and load (set size of overall targets/non-targets presented).

# define lists
ntargList = [n_hex,n_penta1,n_penta2,n_tri1,n_tri2]
distPosList = [(-100,0),(100,0)]
targPosList = [(0,50),(50,25),(50,-25),(0,-50),(-50,-25),(-50,25)]
loadList = [1,2,3,4,5,6]

Under Begin Routine, I shuffled the lists, and selected a random load, target position, and distractor position and assigned them to new variables.

random.shuffle(ntargList)
random.shuffle(distPosList)
random.shuffle(targPosList)
random.shuffle(loadList)

# select random load 
randLoad = loadList[0]

# select random targ pos
randTargPos = targPosList[0]

# select random dist pos
randDistPos = distPosList[0]

In Builder mode, I made sure target (and distractor) image components had the following parameters:

Image: “$targShape”
Position: “randTargPos”
Size/Orientation: blank
Opacity: 1
Units: From exp settings

And then in the remaining Begin Routine code, I created if else statements to determine how many non target shapes will appear, which positions, which images, depending on which random load number I get:

# load 0
if randLoad < 1:
    nTarg1Img = blank
    nTarg1Pos = targPosList[1]
    nTarg2Img = blank
    nTarg2Pos = targPosList[2]
    nTarg3Img = blank
    nTarg3Pos = targPosList[3]
    nTarg4Img = blank
    nTarg4Pos = targPosList[4]
    nTarg5Img = blank
    nTarg5Pos = targPosList[5]
# load 1
elif randLoad < 2 and randLoad > 0:
    nTarg1Img = nTargList[0]
    nTarg1Pos = targPosList[1]
    nTarg2Img = blank
    nTarg2Pos = targPosList[2]
    nTarg3Img = blank
    nTarg3Pos = targPosList[3]
    nTarg4Img = blank
    nTarg4Pos = targPosList[4]
    nTarg5Img = blank
    nTarg5Pos = targPosList[5]
# load 2
elif randLoad < 3 and randLoad > 1:
    nTarg1Img = nTargList[0]
    nTarg1Pos = targPosList[1]
    nTarg2Img = nTargList[1]
    nTarg2Pos = targPosList[2]
    nTarg3Img = blank
    nTarg3Pos = targPosList[3]
    nTarg4Img = blank
    nTarg4Pos = targPosList[4]
    nTarg5Img = blank
    nTarg5Pos = targPosList[5]
# load 3
elif randLoad < 4 and randLoad > 2:
    nTarg1Img = nTargList[0]
    nTarg1Pos = targPosList[1]
    nTarg2Img = nTargList[1]
    nTarg2Pos = targPosList[2]
    nTarg3Img = nTargList[2]
    nTarg3Pos = targPosList[3]
    nTarg4Img = blank
    nTarg4Pos = targPosList[4]
    nTarg5Img = blank
    nTarg5Pos = targPosList[5]
# load 4
elif randLoad < 5 and randLoad > 3:
    nTarg1Img = nTargList[0]
    nTarg1Pos = targPosList[1]
    nTarg2Img = nTargList[1]
    nTarg2Pos = targPosList[2]
    nTarg3Img = nTargList[2]
    nTarg3Pos = targPosList[3]
    nTarg4Img = nTargList[3]
    nTarg4Pos = targPosList[4]
    nTarg5Img = blank
    nTarg5Pos = targPosList[5]
# load 5
else:
    nTarg1Img = nTargList[0]
    nTarg1Pos = targPosList[1]
    nTarg2Img = nTargList[1]
    nTarg2Pos = targPosList[2]
    nTarg3Img = nTargList[2]
    nTarg3Pos = targPosList[3]
    nTarg4Img = nTargList[3]
    nTarg4Pos = targPosList[4]
    nTarg5Img = nTargList[4]
    nTarg5Pos = targPosList[5]

And then in Builder I made sure all my non-target image components “Image”/“Position” parameters was set to nTargImg1 + nTarg1Pos, with other parameters being the same as the above target/distractor.

After running this experiment file, I received 2 errors:

Traceback (most recent call last):
  File "C:\Users\ronda\Google Drive\grad\projects\11 new PL study\builder and code ver\working version_lastrun.py", line 91, in <module>
    texRes=128, interpolate=True, depth=0.0)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\image.py", line 90, in __init__
    self.ori = float(ori)
TypeError: float() argument must be a string or a number, not 'NoneType'

Line 91 refers to this in the compiled experiment script:

# Initialize components for Routine "criticalTrials"
criticalTrialsClock = core.Clock()
critTarget = visual.ImageStim(
    win=win,
    name='critTarget', 
    image='sin', mask=None,
    ori=None, pos=[0,0], size=None,
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=0.0) ########### line 91

Line 90 refers to the image.py associated with the experiment(? not sure):

        # Other stuff
        self._imName = image
        self.isLumImage = None
        self.interpolate = interpolate
        self.flipHoriz = flipHoriz
        self.flipVert = flipVert
        self._requestedSize = size
        self._origSize = None  # updated if an image texture gets loaded
        self.size = val2array(size)
        self.pos = numpy.array(pos, float)
        self.ori = float(ori) ############# line 90
        self.depth = depth

I haven’t a clue as to what these lines of code are referring to! If anyone could help me on this matter, I’d deeply appreciate it!

Yep that’s the correct location that it is referring to! ori in that code is taken from whatever you supplied to the Image as ori, you’ve got it set to None which the image doesn’t like as it has to be a float. If you set it to 0.0 that should fix it. You can find this in Builder in the “Advanced” tab for the Image, the field labelled “Orientation $”.

1 Like

Thanks Todd, what a silly mistake!