Previous topic

RadialStim

Next topic

Rect

This Page

Quick links

RatingScale

class psychopy.visual.RatingScale(win, scale='<default>', choices=None, low=1, high=7, lowAnchorText=None, highAnchorText=None, precision=1, textSizeFactor=1.0, textColor='LightGray', textFont='Helvetica Bold', showValue=True, showScale=True, showAnchors=True, showAccept=True, acceptKeys='return', acceptPreText='key, click', acceptText='accept?', leftKeys='left', rightKeys='right', lineColor='White', markerStyle='triangle', markerColor=None, markerStart=False, markerExpansion=1, customMarker=None, escapeKeys=None, allowSkip=True, skipKeys='tab', mouseOnly=False, singleClick=False, displaySizeFactor=1.0, stretchHoriz=1.0, pos=None, minTime=1.0, maxTime=0.0, disappear=False, name='', autoLog=True)

A class for getting numeric or categorical ratings, e.g., on a 1-to-7 scale.

Returns a re-usable rating-scale object having a .draw() method, with a customizable visual appearance. Tries to provide useful default values.

The .draw() method displays the rating scale only (not the item to be rated), handles the subject’s response, and updates the display. When the subject responds, .noResponse goes False (i.e., there is a response). You can then call .getRating() to obtain the rating, .getRT() to get the decision time, or .reset() to restore the scale (for re-use). The experimenter has to handle the item to be rated, i.e., draw() it in the same window each frame. A RatingScale instance has no idea what else is on the screen. The subject can use the arrow keys (left, right) to move the marker in small increments (e.g., 1/100th of a tick-mark if precision = 100).

Auto-rescaling happens if the low-anchor is 0 and high-anchor is a multiple of 10, just to reduce visual clutter.

Example 1:

*Default 7-point scale*::

    myItem = <create your text, image, movie, ...>
    myRatingScale = visual.RatingScale(myWin)
    while myRatingScale.noResponse:
        myItem.draw()
        myRatingScale.draw()
        myWin.flip()
    rating = myRatingScale.getRating()
    decisionTime = myRatingScale.getRT()

Example 2:

Mouse-free. Considerable customization is possible. For fMRI, if your response
box sends keys 1-4, you could specify left, right, and accept keys, and no mouse:

    myRatingScale = visual.RatingScale(myWin, markerStart=4,
        leftKeys='1', rightKeys = '2', acceptKeys='4')

Example 3:

Non-numeric choices (categorical, unordered):

    myRatingScale = visual.RatingScale(myWin, choices=['agree', 'disagree'])
    myRatingScale = visual.RatingScale(myWin,
                        choices=['cherry', 'apple', True, 3.14, 'pie'])

str(item) will be displayed, but the value returned by
getResponse() will be of type you gave it::

    myRatingScale = visual.RatingScale(myWin, choices=[True, False])

So if you give boolean values and the subject chooses False,
getResponse() will return False (bool) and not 'False' (str).

See Coder Demos -> stimuli -> ratingScale.py for examples. As another example, fMRI_launchScan.py uses a rating scale for the experimenter to choose between two modes (and not for subjects giving ratings).

The Builder RatingScale component gives a restricted set of options, but also allows full control over a RatingScale (via ‘customizeEverything’).

Author :

2010 Jeremy Gray, 2011 updates

Parameters :
win :

A Window object (required)

scale :

string, explanation of the numbers to display to the subject, shown above the line; default = ‘<low>=not at all, <high>=extremely’ to suppress all text above the line, set showScale=False

choices :

a list of items which the subject can choose among; (takes precedence over low, high, lowAnchorText, highAnchorText, showScale)

low :

lowest numeric rating / low anchor (integer, default = 1)

high :

highest numeric rating / high anchor (integer, default = 7; at least low+1)

lowAnchorText :

text to dsiplay for the low end of the scale (default = numeric low value)

highAnchorText :

text to display for the high end of the scale (default = numeric high value)

precision :

portions of a tick to accept as input [1,10,100], default = 1 tick (no fractional parts)

Note

left/right keys will move the marker by one portion of a tick.

textSizeFactor :

control the size of text elements of the scale. for larger than default text (expand) set > 1; for smaller, set < 1

textColor :

color to use for anchor and scale text (assumed to be RGB), default = ‘LightGray’

textFont :

name of the font to use, default = ‘Helvetica Bold’

showValue :

show the subject their currently selected number, default = True

showScale :

show the scale text (the text above the line), default = True if False, will not show any text above the line

showAnchors :

show the two end points of the scale (low, high), default = True

showAccept :

show the button to click to accept the current value by using the mouse, default = True

Note

If showAccept is False and acceptKeys is empty, acceptKeys is reset to [‘return’] to give the subject a way to respond.

acceptKeys :

list of keys that mean “accept the current response”, default = [‘return’]

acceptPreText :

text to display before any value has been selected

acceptText :

text to display in the ‘accept’ button after a value has been selected

leftKeys :

list of keys that mean “move leftwards”, default = [‘left’]

rightKeys :

list of keys that mean “move rightwards”, default = [‘right’]

lineColor :

color to use for the scale line, default = ‘White’

markerStyle :

‘triangle’ (DarkBlue), ‘circle’ (DarkRed), or ‘glow’ (White)

markerColor :

None = use defaults; or any legal RGB colorname, e.g., ‘#123456’, ‘DarkRed’

markerStart :

False, or the value in [low..high] to be pre-selected upon initial display

markerExpansion :

how much the glow marker expands when moving to the right; 0=none, negative shrinks; try 10 or -10

customMarker :

allows for a user-defined marker; must have a .draw() method, such as a TextStim() or PatchStim()

escapeKeys :

keys that will quit the experiment, calling core.quit(). default = [ ] (none)

allowSkip :

if True, the subject can skip an item by pressing a key in skipKeys, default = True

skipKeys :

list of keys the subject can use to skip a response, default = [‘tab’]

Note

to require a response to every item, use allowSkip=False

mouseOnly :

require the subject use the mouse only (no keyboard), default = False. can be used to avoid competing with other objects for keyboard input.

Note

mouseOnly=True and showAccept=False is a bad combination, so showAccept wins (mouseOnly is reset to False); similarly, mouseOnly and allowSkip can conflict, because skipping an item is done via key press (mouseOnly wins) mouseOnly=True is helpful if there will be something else on the screen expecting keyboard input

singleClick :

enable a mouse click to both indicate and accept the rating, default = False. note that the ‘accept’ box is visible, but clicking it has no effect, its just to display the value. a legal key press will also count as a singleClick.

pos : tuple (x, y)

where to position the rating scale (x, y) in terms of the window’s units (pix, norm); default (0.0, -0.4) in norm units

displaySizeFactor :

how much to expand or contract the overall rating scale display (not just the line length)

stretchHoriz:

multiplicative factor for stretching (or compressing) the scale horizontally (3 -> use the whole window); like displaySizeFactor, but only in the horizontal direction

minTime :

number of seconds that must elapse before a reponse can be accepted, default = 1.0s

maxTime :

number of seconds after which a reponse cannot be made accepted. if maxTime <= minTime, there’s unlimited time. default = 0.0s (wait forever)

disappear :

if True, the rating scale will be hidden after a value is accepted; useful when showing multiple scales. The default is to remain on-screen.

name : string

The name of the object to be using during logged messages about this stim

autolog :

whether logging should be done automatically

draw()

Update the visual display, check for response (key, mouse, skip).

sets response flags as appropriate (self.noResponse, self.timedOut). draw() only draws the rating scale, not the item to be rated

getRT()

Returns the seconds taken to make the rating (or to indicate skip). Returns None if no rating available. or maxTime if the response timed out.

getRating()

Returns the numerical rating. None if the subject skipped this item; False if not available.

reset()

restores the rating-scale to its post-creation state (as “untouched” by the subject).

does not restore the scale text description (such reset is needed between items when rating multiple items)

setDescription(scale)

Method to set the description that appears above the line, (e.g., “1=not at all...extremely=7”) The text will not be visible if showScale is False. This can be useful if re-using the same RatingScale object to get ratings of different dimentions. While its possible to just assign to rs.scaleDescription.text, its better to do rs.setDescription() which records the appropriate change in the log file.

setMarkerPos(value)

Method to allow the experimenter to set the marker’s position on the scale (in units of tick marks). This method can also set the index within a list of choices (which start at 0). No range checking is done.

Assuming you have defined rs = RatingScale(...), you can specify a tick position directly:

rs.setMarkerPos(2)
or do range checking, precision management, and auto-rescaling::
rs.setMarkerPos(rs._getMarkerFromTick(2))
To work from a screen coordinate, such as the X position of a mouse click::
rs.setMarkerPos(rs._getMarkerFromPos(mouseX))