To import RatingScale, you can either use:
from psychopy_legacy.visual.ratingscale import RatingScale
or, any time after psychopy.plugins.activatePlugins has been called:
from psychopy.visual import RatingScale
A class for obtaining ratings, e.g., on a 1-to-7 or categorical scale. This is a lazy-imported class, therefore import using full path from psychopy.visual.ratingscale import RatingScale when inheriting from it.
A RatingScale instance is a re-usable visual object having a draw()
method, with customizable appearance and response options. draw()
displays the rating scale, handles the subject’s mouse or key responses,
and updates the display. When the subject accepts a selection,
.noResponse
goes False
(i.e., there is a response).
You can call the getRating()
method anytime to get a rating,
getRT()
to get the decision time, or getHistory()
to obtain
the entire set of (rating, RT) pairs.
There are five main elements of a rating scale: the scale (text above the line intended to be a reminder of how to use the scale), the line (with tick marks), the marker (a moveable visual indicator on the line), the labels (text below the line that label specific points), and the accept button. The appearance and function of elements can be customized by the experimenter; it is not possible to orient a rating scale to be vertical. Multiple scales can be displayed at the same time, and continuous real-time ratings can be obtained from the history.
The Builder RatingScale component gives a restricted set of options, but also allows full control over a RatingScale via the ‘customize_everything’ field.
A RatingScale instance has no idea what else is on the screen. The experimenter has to draw the item to be rated, and handle escape to break or quit, if desired. The subject can use the mouse or keys to respond. Direction keys (left, right) will move the marker in the smallest available increment (e.g., 1/10th of a tick-mark if precision = 10).
Example 1:
A basic 7-point scale:
ratingScale = visual.RatingScale(win) item = <statement, question, image, movie, ...> while ratingScale.noResponse: item.draw() ratingScale.draw() win.flip() rating = ratingScale.getRating() decisionTime = ratingScale.getRT() choiceHistory = ratingScale.getHistory()
Example 2:
For fMRI, sometimes only a keyboard can be used. If your response box sends keys 1-4, you could specify left, right, and accept keys, and not need a mouse:
ratingScale = visual.RatingScale( win, low=1, high=5, markerStart=4, leftKeys='1', rightKeys = '2', acceptKeys='4')
Example 3:
Categorical ratings can be obtained using choices:
ratingScale = visual.RatingScale( win, choices=['agree', 'disagree'], markerStart=0.5, singleClick=True)
For other examples see Coder Demos -> stimuli -> ratingScale.py.
2010 Jeremy Gray: original code and on-going updates
2012 Henrik Singmann: tickMarks, labels, ticksAboveLine
2014 Jeremy Gray: multiple API changes (v1.80.00)
Commit and optionally log a response and the action.
Determines whether the stimulus should be automatically drawn on every frame flip.
Value should be: True or False. You do NOT need to set this on every frame flip!
Whether every change in this stimulus should be auto logged.
Value should be: True or False. Set to False if your stimulus is updating frequently (e.g. updating its position every frame) and you want to avoid swamping the log file with messages that aren’t likely to be useful.
Update the visual display, check for response (key, mouse, skip).
Sets response flags: self.noResponse, self.timedOut. draw() only draws the rating scale, not the item to be rated.
Return a list of the subject’s history as (rating, time) tuples.
The history can be retrieved at any time, allowing for continuous ratings to be obtained in real-time. Both numerical and categorical choices are stored automatically in the history.
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. Returns the time elapsed so far if no rating has been accepted yet (e.g., for continuous usage).
Returns the final, accepted rating, or the current value.
The rating is None if the subject skipped this item, took longer
than maxTime
, or no rating is
available yet. Returns the currently indicated rating even if it has
not been accepted yet (and so might change until accept is pressed).
The first rating in the list will have the value of
markerStart (whether None, a numeric value, or a choice value).
The name (str) of the object to be using during logged messages about this stim. If you have multiple stimuli in your experiment this really helps to make sense of log files!
If name = None your stimulus will be called “unnamed <type>”, e.g. visual.TextStim(win) will be called “unnamed TextStim” in the logs.
Restores the rating-scale to its post-creation state.
The history is cleared, and the status is set to NOT_STARTED. Does not restore the scale text description (such reset is needed between items when rating multiple items)
Sets autoDraw. Usually you can use ‘stim.attribute = value’ syntax instead, but use this method to suppress the log message.
Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message.
Method to set the brief description (scale).
Useful when using the same RatingScale object to rate several dimensions. setDescription(None) will reset the description to its initial state. Set to a space character (’ ‘) to make the description invisible.
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))