psychopy.org | Reference | Downloads | Github

Calling Coordinates from Excel, e.g., [135,135]

OS Win10:
PsychoPy version v3.0.5 (Psychopy 3):
Standard Standalone? (y)

What are you trying to achieve?:
To specify location of the Image, I write $eval(PixelLocation) in the “position” field of Image Properties, which calls the coordinates from a column in Excel called “PixelLocation”, (e.g., row 1= [135,135], row 2= [0,135]).
What specifically went wrong when you tried that?:
However, this produces the error:

type error eval() arg 1 must be string bytes or code object

If I try changing the position field to $PixelLocation, it produces the following error:

setAttribute(self, ‘pos’, val2array(newPos, False), log, operation)
value = numpy.array(value,float)
ValueError: could not convert string to float: ‘[135,0]’

It’s odd because $eval(PixelLocation) has worked with other experiments (using the same psychopy version) but does not work in this case -any alternatives that are more reliable than eval()?

Hi @Ryan_Blything, I can only replicate this error if I use a tuple (round brackets) for my position in the conditions file. If I use square brackets (as I see you have) I cannot create this error. Would you mind sharing a minimal working example of the error, with the conditions file?

Thanks very much.

I’ve reattached the files because my previous upload was faulty.SameDiff_M.psyexp (131.7 KB)
Stim.xlsx (11.3 KB)

@Ryan_Blything, try removing the eval call on your positions. You should not need to do this, you should be able to just take the position variable from your conditions file and add this to the position param of your image stim e.g., PixelLocationA in pos to update on every repeat. But, you are saying this does not work as well? I take it you are using standalone PsychoPy?

Update: I’ve discovered what was wrong and I’m embarassed to say it was unrelated to the value of pos field. I hadn’t mentioned (in order to simplify the experiment) that I import the excel sheet via code component (for records, I’ve outlined this below). I turned out that my excel sheet did not correspond to this (i.e., PixLocationB was in column 4 as opposed to 3. This is why $eval(PixLocationB) did not work and I’m pleased to say it does now work. Many apologies for taking your time.

for rowx in range(1,num_items+1): #read in values of all columns on this row
…row = insheet.row_values(rowx) #print value of column A for this row #print row[0]
…ImageA.append(row[0])
…PixLocationA.append(row[1])
…PixLocationB.append(row[2])

1 Like