psychopy.org | Reference | Downloads | Github

Builder inserts useless asarray calls in py code

OS (e.g. Win10): MacOs 11.2.2
PsychoPy version (e.g. 1.84.x): 2021.1.2
Standard Standalone? (y/n) If not then what?: y

Hi,
I have several text component in which the Letter height is set to a variable, TextHeight, at every repeat.
In some of them, but not systematically the code inserts a call to asarray

FbText.setHeight(asarray(textHeight))
InstrScr3a.setHeight(textHeight)

which then throws an error at execution.

I am scratching my head and cannot understand what causes the difference. Is this a known bug ?

Try this

Nope, that one I know, it solves the problem for .js code. The problem I now see is in the python code.

Check for excessive dollar signs.

Yep. tried both, to no avail. Very irritating, specially given that I think it did not happen earlier today. Cant understand what could have caused it.

You could try downloading 2021.1.3 from github. Personally, I’m not yet ready to leave 2020.2.10

I think i tried with 2021.1.3 at some point also, no success.
Out of despair, I added a python function definition in a code block before experiment, as you proposed for the javascript version :

def asarray(something):
    return(something)

and it works for me. So definitely these calls to asarray() seem to serve no use.

asarray is added when the value of the input box can’t be easily converted to a float, for example if it’s a variable name rather than a constant. The reason we do this is to make sure that the input is capable of matrix calculations - for example, if you gave a list of values and the component needed to multiply each by something.

I think what’s probably happening is that asarray is added because the variable name itself isn’t a number, but because of this it isn’t converted to a float within the array, so the array ends up being array('1') rather than array(1), hence the error. If your variable is just one value at a time, you could set the value to float(textHeight), which will compile as asarray(float(textHeight)) and give you an array with one numeric value, as intended.

Hi, Todd, thanks.

I tried entering float(textHeight) as advised (if I got it right), and it does not solve the problem.
Also, unclear why asarray is added at compilation in some places but not in other.

For info, here is the error Traceback

Traceback (most recent call last):
  File "/Users/ac/Documents/LetterWidth/Script/WidthEstimation_V3_lastrun.py", line 529, in <module>
    Hello.setHeight(asarray(float(textHeight)))
  File "/Applications/PsychoPy/PsychoPy2021.1.2.app/Contents/Resources/lib/python3.6/psychopy/visual/text.py", line 270, in setHeight
    setAttribute(self, 'height', height, log)
  File "/Applications/PsychoPy/PsychoPy2021.1.2.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 141, in setAttribute
    setattr(self, attrib, value)
  File "/Applications/PsychoPy/PsychoPy2021.1.2.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 35, in __set__
    value=value)
  File "/Applications/PsychoPy/PsychoPy2021.1.2.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py", line 160, in logAttrib
    and (value.ndim > 2 or len(value) > 2):
TypeError: len() of unsized object

Happy to give you access to the code if useful.

Ah, giving us that error traceback makes a huge difference - Todd and Wakefield were assuming (naturally) you had a different bug to the one you’ve got but we can look into this different one.

This is fixed in release 2021.1.4, which I’m currently building and uploading for testing.

1 Like

I think that might be my jumping on point for 2021.

Will thisN still be broken?

I believe thisN has been working for a while - I forget which version it was fixed in