Sarah
Sarah

Reputation: 35

Error: unsupported operand type(s) PsychoPy

I am stuck with the following question: I have designed a PsychoPy Experiment in Windows, Version 1.82.01. It runs perfectly there.

Now I have copied the same experiment on a MacBook Air under the version 1.83.01.

Since then, the experiment starts, but after a while, I get the following error message

#Running:  
/Users/Kataha/Desktop/Experiment/Experiment_FFOV_Kinder3_lastrun.py #
2015-12-05 15:26:39.876 python[1314:117629]
ApplePersistenceIgnoreState: Existing state will not be touched. 
New state will be written to /var/folders/c8/
qy0wd2ws3r115rg30wxxg6940000gn/T/org.psychopy.PsychoPy2.savedState
Traceback (most recent call last):
File
"/Users/Kataha/Desktop/Experiment/Experiment_FFOV_Kinder3_lastrun.py",
line 389, in <module>
if Fix_kreuz.status == STARTED and t >= (0.0 + (SOA-win.monitorFramePeriod*0.75)): 
#most of one frame period left

TypeError: unsupported operand type(s) for -: 'unicode' and 'numpy.float64'

The code in line 389 looks like the following:

# *Fix_kreuz* updates
    if t >= 0.0 and Fix_kreuz.status == NOT_STARTED:
        # keep track of start time/frame for later
        Fix_kreuz.tStart = t  # underestimates by a little under one frame
        Fix_kreuz.frameNStart = frameN  # exact frame index
        Fix_kreuz.setAutoDraw(True)
    if Fix_kreuz.status == STARTED and t >= (0.0 + (SOA-win.monitorFramePeriod*0.75)): #most of one frame period left
        Fix_kreuz.setAutoDraw(False)

The variable SOA is defined in an excel sheet: Excel Sheet with variables

I cannot figure out, what the problem is. I hope, someone can help me. Thank you!

Upvotes: 1

Views: 186

Answers (2)

Michael MacAskill
Michael MacAskill

Reputation: 2421

In your Excel file, notice that in the SOA column, the '0.5' values are left-justified whereas the '3' values are right justified. In Excel, left-justified cells indicate that those are text values rather than numeric. Compare to the first two columns, which are all text (and all left-justified), and the last column, which is all numeric (and all right-justified).

You could try exporting this file to .csv rather than native .xlsx. If these are actually numeric values, then that column would be read by PsychoPy as numeric. But you should probably identify what is making Excel regard those entries in that column as being text. Can't tell from the font, but sometimes a cause for this is typing "oh point five" rather than "zero point five".

This is consistent with @Michiel's answer that unicode (i.e. text) values are polluting the SOA variable, which should contain floating point variables. But it isn't consistent with your type test, which found that the value was a float.

Upvotes: 1

Michiel Overtoom
Michiel Overtoom

Reputation: 1619

Apparently the variable SOA contains an unicode value:

... SOA-win.monitorFramePeriod ...

unsupported operand type(s) for -: 'unicode' and 'numpy.float64' 

You don't show where SOA is defined. Can you show that, or perhaps somewhere post the entire project? To verify what the types exactly are, you could add these lines:

print "SOA=", SOA, typeof(SOA)
print "monitorFramePeriod=", win.monitorFramePeriod, typeof(SOAwin.monitorFramePeriod)

before the line

if Fix_kreuz.status == STARTED ...

A possible fix might be, but this is a wild guess:

if Fix_kreuz.status == STARTED and t >= (0.0 + (float(SOA)-win.monitorFramePeriod*0.75)): 

Upvotes: 1

Related Questions