psychopy.org | Reference | Downloads | Github

Set Scale Description w/ Conditions File Error

I am attempting to retrieve the text strings or indexes of the conditions specified in the csv retrieved by the TrialHandler. I am trying to modify the builder code. How could I go about doing this?

#trial handler
    trials_3 = data.TrialHandler(nReps=1, method='random', 
            extraInfo=expInfo, originPath=-1,
            trialList=data.importConditions(u'comp.xlsx'),
            seed=None, name='trials_3')
        thisExp.addLoop(trials_3)  # add the loop to the experiment
        thisTrial_3 = trials_3.trialList[0]  # so we can initialise stimuli with some values

#set labels function
            def setLabel():
                if trials_3.trialList == [0]:
                    return [u'neutral', u' very strong']
                elif trials_3.trialList == [1]:
                    return [u'neutral', u' very strong']
                else:
                    return [u'no compassion', u'a lot of compassion']
                    
            rating_9 = visual.RatingScale(win=win, name='rating_9', marker=u'triangle', size=1.0,
                pos=[0.0, -0.4], low=0, high=10, labels=setLabel(), scale=u'')

Hi

(1) Almost certainly you shouldn’t be modifying the Builder code. Instead, insert a code component within the Builder interface and put your code there, in the relevant tab. This allows you to keep using the Builder interface. If you try to modify the Builder code manually, you can no longer use the graphical Builder interface.

(2) You need to specify exactly what you mean by " text strings or indexes of the conditions specified in the csv". But hopefully this might help:
The TrialHandler turns each row of the csv file into a dictionary, specifying the column names from the file as the keys of the dictionary and the row contents as the corresponding values. So if you want the column names, you can do something like this:

# get column names:
column_names = thisTrial_3.keys()

# get parameter values for this trial:
parameter_values = thisTrial_3.values()

Hi Michael,

Thank you, I have moved this discussion to the Builder Discourse.

To take a few steps back, I am attempting to set two parameters in my conditions file to populate the ‘Scale description’ and also the ‘Labels’ attribute randomly in the Rating Dialogue Box Properties. I used the ‘$’ symbol to specify the parameters to look for in the conditions file (e.g., $compassion). I have set the routine, which only contains the rating scale, to loop randomly based on said conditions file: 3 conditions, with 2 parameters [compassion, labels]. An error is returned:

rating_9 = visual.RatingScale(win=win, name='rating_9',
marker=u'triangle', size=1.0, pos=[0.0, -0.4], low=0,
high=10, labels=[u'$labels'], scale=compassion)
NameError: name 'compassion' is not defined

Thanks again.