plots

Classes to plot data in the GUI.

Todo

Add all possible plot objects and options in list.

Note

Plot objects need to be added to PLOT_LIST in order to be reachable.

autopilot.core.plots.gui_event(fn)[source]

Wrapper/decorator around an event that posts GUI events back to the main thread that our window is running in.

Parameters:fn (callable) – a function that does something to the GUI
class autopilot.core.plots.Plot_Widget[source]

Bases: PySide.QtGui.QWidget

Main plot widget that holds plots for all pilots

Essentially just a container to give plots a layout and handle any logic that should apply to all plots.

Variables:
  • logger (logging.Logger) – The ‘main’ logger
  • plots (dict) – mapping from pilot name to Plot
init_plots(pilot_list)[source]

For each pilot, instantiate a Plot and add to layout.

Parameters:pilot_list (list) – the keys from Terminal.pilots
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Plot(pilot, x_width=50)[source]

Bases: PySide.QtGui.QWidget

Widget that hosts a pyqtgraph.PlotWidget and manages graphical objects for one pilot depending on the task.

listens

Key Method Description
‘START’ l_start() starting a new task
‘DATA’ l_data() getting a new datapoint
‘STOP’ l_stop() stop the task
‘PARAM’ l_param() change some parameter

Plot Parameters

The plot is built from the PLOT={data:plot_element} mappings described in the Task class. Additional parameters can be specified in the PLOT dictionary. Currently:

  • continuous (bool): whether the data should be plotted against the trial number (False or NA) or against time (True)
  • chance_bar (bool): Whether to draw a red horizontal line at chance level (default: 0.5)
  • chance_level (float): The position in the y-axis at which the chance_bar should be drawn
  • roll_window (int): The number of trials Roll_Mean take the average over.
Variables:
  • pilot (str) –

    The name of our pilot, used to set the identity of our socket, specifically:

    'P_{pilot}'
    
  • infobox (QtGui.QFormLayout) – Box to plot basic task information like trial number, etc.
  • info (dict) –

    Widgets in infobox:

    • ’N Trials’: QtGui.QLabel,
    • ’Runtime’ : Timer,
    • ’Session’ : QtGui.QLabel,
    • ’Protocol’: QtGui.QLabel,
    • ’Step’ : QtGui.QLabel
  • plot (pyqtgraph.PlotWidget) – The widget where we draw our plots
  • plot_params (dict) – A dictionary of plot parameters we receive from the Task class
  • data (dict) – A dictionary of the data we’ve received
  • plots (dict) – The collection of plots we instantiate based on plot_params
  • node (Net_Node) – Our local net node where we listen for data.
  • state (str) – state of the pilot, used to keep plot synchronized.
Parameters:
  • pilot (str) – The name of our pilot
  • x_width (int) – How many trials in the past should we plot?
init_plots(**kwargs)[source]

Make pre-task GUI objects and set basic visual parameters of self.plot

l_start(**kwargs)[source]

Starting a task, initialize task-specific plot objects described in the Task.PLOT attribute.

Matches the data field name (keys of Task.PLOT ) to the plot object that represents it, eg, to make the standard nafc plot:

{'target'   : 'point',
 'response' : 'segment',
 'correct'  : 'rollmean'}
Parameters:value (dict) –

The same parameter dictionary sent by Terminal.toggle_start(), including

  • current_trial
  • step
  • session
  • step_name
  • task_type
l_data(**kwargs)[source]

Receive some data, if we were told to plot it, stash the data and update the assigned plot.

Parameters:value (dict) – Value field of a data message sent during a task.
l_stop(**kwargs)[source]

Clean up the plot objects.

Parameters:value (dict) – if “graduation” is a key, don’t stop the timer.
l_param(value)[source]

Warning

Not implemented

Parameters:value
l_state(value)[source]

Pilot letting us know its state has changed. Mostly for the case where we think we’re running but the pi doesn’t.

Parameters:value (Pilot.state) – the state of our pilot
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Point(color=(0, 0, 0), size=5, **kwargs)[source]

Bases: pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem

A simple point.

Variables:
  • brush (QtGui.QBrush) –
  • pen (QtGui.QPen) –
Parameters:
  • color (tuple) – RGB color of points
  • size (int) – width in px.
update(data)[source]
Parameters:data (numpy.ndarray) – an x_width x 2 array where column 0 is trial number and column 1 is the value, where value can be “L”, “C”, “R” or a float.
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Segment(**kwargs)[source]

Bases: pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem

A line segment that draws from 0.5 to some endpoint.

update(data)[source]

data is doubled and then every other value is set to 0.5, then setData() is used with connect=’pairs’ to make line segments.

Parameters:data (numpy.ndarray) – an x_width x 2 array where column 0 is trial number and column 1 is the value, where value can be “L”, “C”, “R” or a float.
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Roll_Mean(winsize=10, **kwargs)[source]

Bases: pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem

Shaded area underneath a rolling average.

Typically used as a rolling mean of corrects, so area above and below 0.5 is drawn.

Parameters:winsize (int) – number of trials in the past to take a rolling mean of
update(data)[source]
Parameters:data (numpy.ndarray) – an x_width x 2 array where column 0 is trial number and column 1 is the value.
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Shaded(**kwargs)[source]

Bases: pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem

Shaded area for a continuous plot

update(data)[source]
Parameters:data (numpy.ndarray) – an x_width x 2 array where column 0 is time and column 1 is the value.
staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.Timer[source]

Bases: PySide.QtGui.QLabel

A simple timer that counts… time…

Uses a QtCore.QTimer connected to Timer.update_time() .

start_timer(update_interval=1000)[source]
Parameters:update_interval (float) – How often (in ms) the timer should be updated.
stop_timer()[source]

you can read the sign ya punk

update_time()[source]

Called every (update_interval) milliseconds to set the text of the timer.

staticMetaObject = <PySide.QtCore.QMetaObject object>
class autopilot.core.plots.HLine[source]

Bases: PySide.QtGui.QFrame

A Horizontal line.

staticMetaObject = <PySide.QtCore.QMetaObject object>
autopilot.core.plots.PLOT_LIST = {'point': <class 'autopilot.core.plots.Point'>, 'rollmean': <class 'autopilot.core.plots.Roll_Mean'>, 'segment': <class 'autopilot.core.plots.Segment'>, 'shaded': <class 'autopilot.core.plots.Shaded'>}

A dictionary connecting plot keys to objects.

Todo

Just reference the plot objects.