The hardware Module

Olfactometer Provides an interface to the ValveLink devices used to control olfactometers.
Gustometer Provide an interface to the Burghart GU002 gustometer.
AnalogInput Analog data acquisition using a National Instruments board.
Trigger Send triggers, e.g.
EEG Provides a remote-control interface to PyCorder.

Olfactometer

class pphelper.hardware.Olfactometer(ni_lines=u'Dev1/port0/line0:7', ni_trigger_line=None, ni_task_name=u'Olfactometer', use_threads=True, test_mode=False)

Bases: pphelper.hardware._StimulationApparatus

Provides an interface to the ValveLink devices used to control olfactometers.

Parameters:
  • ni_lines (string, optional) – The lines of the NI board to use as output channel. Defaults to Dev1/line0:7.
  • ni_trigger_line (string, optional) – A line on which to generate an additional trigger pulse as the olfactometer stimulation is initiated. This can be used to start the acquisition of PID data, for example.
  • ni_task_name (string, optional) – The name of the NI DAQ task to create. Defaults to Olfactometer.
  • use_threads (bool, optional) – Whether a Python thread should be created when select_stimulus is called. This thread would then allow non-blocking stimulation. Defaults to True.
  • test_mode (bool, optional) – If True, the NI board will not actually be initialized or used in any manner. This allows for testing the program logic on a computer without a DAQ card. Defaults to False.
add_stimulus(name, bitmask, duration=1, bitmask_offset=None, trigger_time=None, replace=False, **kwargs)

Add a stimulus to the stimulus set of this apparatus.

Parameters:
  • name (string) – A unique identifier of the stimulus to add.
  • bitmask (array_like) – The bitmask specifying the valve positions required to present this stimulus.
  • duration (float, optional) – The duration of the stimulation, specified in seconds. Defaults to 1 second.
  • bitmask_offset (array_like, optional) – The bitmask specifying the valve positions after the stimulation has finished. If not specified, all valves will be closed at the end of the stimulation.
  • trigger_time (float, optional) – The time (in terms of the psychopy.core.getTime timebase) at which the stimulation should be triggered. If None, trigger immediately. Defaults to None.
  • replace (bool, optional) – Whether an already existing stimulus of the same name should be replaced or not. Defaults to False.

Notes

Any additional keyword arguments will be added as additional stimulus properties.

remove_stimulus(name)

Remove the specified stimulus, identified by its unique name, from the stimulus list.

Parameters:name (string) – The unique name of the stimulus to remove.
select_stimulus(name)

Select the specified stimulus for the next stimulation.

Parameters:name (string) – The unique name of the stimulus to select.
stimulate(blocking_wait=False)

Start the stimulation with the currently selected stimulus.

The trigger pulse will open the valves. They are then left open for the intended duration of the stimulus. After that, they will be switched to the offset state specified by the stimulus.

Parameters:blocking_wait (bool, optional) – Specifies whether the stimulation thread should be joined or not, i.e. whether we should wait for it to finish (blocking other operations), or return immediately. This parameter will be ignored if threads are not used for stimulation. Defaults to False, i.e. non-blocking behavior.

Notes

stimulate invokes _stimulate, which itself unsets the currently selected stimulus at the end of the stimulation. You have to invoke select_stimulus again before you can call stimulate again.

stimuli

A list of all stimuli added to this stimulation apparatus.

stimulus

The currently selected stimulus.

This stimulus will be presented when invoking stimulate. It can be set using select_stimulus.

test_mode

Gustometer

class pphelper.hardware.Gustometer(pulse_duration=0.1, pause_duration=0.2, gusto_ip=u'192.168.0.1', gusto_port=40175, ni_trigger_in_line=u'PFI14', ni_trigger_in_task_name=u'GustometerIn', use_threads=False, test_mode=False)

Bases: pphelper.hardware._StimulationApparatus

Provide an interface to the Burghart GU002 gustometer.

Parameters:
  • pulse_duration (float, optional) – The duration of one stimulation pulse, in seconds. Defaults to 0.1.
  • pause_duration (float, optional) – The duration of the spray pause between two pulses in seconds. Defaults to 0.2
  • gusto_ip (string, optional) – The IP address of the gustometer control computer. Defaults to 192.168.0.1.
  • gusto_port (int, optional) – The port on which the control software on the gustometer control computer is listening for a connection. This should usually not need to be changed. Defaults to 40175.
  • ni_trigger_in_line (string, optional) – The counter input line on the NI board which shall be used to receive the trigger pulse emitted by the gustometer as soon presentation of the requested stimulus has actually started. Defaults to Dev1/ctr0.
  • ni_trigger_in_task_name (string, optional) – The name to assign to the trigger input task. Defaults to GustometerIn.
  • use_threads (bool, optional) – Whether a Python thread should be created when select_stimulus is called. This thread would then allow non-blocking stimulation. Defaults to False.
  • test_mode (bool, optional) – If True, the NI board will not actually be initialized or used in any manner. This allows for testing the program logic on a computer without a DAQ card. Defaults to False.
add_stimulus(name, classnum, trigger_time=None, wait_for_gusto_trigger=True, replace=False, **kwargs)

Add a stimulus to the stimulus set of this apparatus.

Parameters:
  • name (string) – A unique identifier of the stimulus to add.
  • classnum (int) – The stimulus class number, as defined in the Gusto Control software.
  • wait_for_gusto_trigger (bool, optional) – Whether to block program execution and wait until we receive the trigger from the gustometer, informing us about the precise time of stimulus onset. Defaults to True.
  • trigger_time (float, optional) – The time (in terms of the psychopy.core.getTime timebase) at which the stimulation should be triggered. If None, trigger immediately. Defaults to None.
  • replace (bool, optional) – Whether an already existing stimulus of the same name should be replaced or not. Defaults to False.

Notes

Any additional keyword arguments will be added as additional stimulus properties.

load_classfile(filename)

Load a classes file in the Gusto Control software.

Parameters:filename (string) – The filename of the classes file to be loaded, including the file extension (typically .cla).
remove_stimulus(name)

Remove the specified stimulus, identified by its unique name, from the stimulus list.

Parameters:name (string) – The unique name of the stimulus to remove.
select_stimulus(name)

Select the specified stimulus for the next stimulation.

Parameters:name (string) – The unique name of the stimulus to select.
set_mode(mode)

Switch between edit experiment mode.

In edit mode, the background stimulus presentation is off. In experiment mode, the background stimulus presentation is on.

Parameters:mode (string) – If edit, switch to edit mode. If experiment or exp, switch to experiment mode.
stimulate(blocking_wait=False)

Start the stimulation with the currently selected stimulus.

Parameters:blocking_wait (bool, optional) – Specifies whether the stimulation thread should be joined or not, i.e. whether we should wait for it to finish (blocking other operations), or return immediately. This parameter will be ignored if threads are not used for stimulation. Defaults to False, i.e. non-blocking behavior.

Notes

stimulate invokes _stimulate, which itself unsets the currently selected stimulus at the end of the stimulation. You have to invoke select_stimulus again before you can call stimulate again.

stimuli

A list of all stimuli added to this stimulation apparatus.

stimulus

The currently selected stimulus.

This stimulus will be presented when invoking stimulate. It can be set using select_stimulus.

test_mode
trigger_conf(duration=0.9, int_taste=100, int_bg=100)

Configure the trigger on the gusto.

Parameters:
  • duration (int, optional) – Trigger duration (stimulation duration) in seconds. Defaults to 0.9s.
  • int_taste (int, optional) – Taste intensity in percent. Defaults to 100%.
  • int_bg (int, optional) – Background intensity in percent. Defaults to 100%.

AnalogInput

class pphelper.hardware.AnalogInput(ni_input_line=u'Dev1/ai0', ni_trigger_line=None, sampling_duration=3, sampling_rate=2000, ni_task_name=u'AnalogInput')

Bases: object

Analog data acquisition using a National Instruments board.

Parameters:
  • ni_input_line (str, optional) – The analog input line to acquire the data from. Defaults to Dev1/ai0.
  • ni_trigger_line (str, optional) – If specified, start the acquisition only after a start trigger (high voltage) on this line has been received. If None, no external trigger is required.
  • sampling_duration (float, optional) – How long to sample, specified in seconds. Defaults to 3 seconds.
  • sampling_rate (int, optional) – At which rate (in Hz) to sample the analog input signal. Defaults to 2000 Hz.
  • ni_task_name (str, optional) – The name of the NIDAQmx task to create. Defaults to AnalogInput.
get_data()

Return the acquired data.

If the acquisition is not finished by the time this method is called, it will first wait until finished (blocking other processing) and then return the data.

samples_to_acquire

The number of samples to acquire in the acquisition. This is the product of the sampling rate and the sampling duration.

sampling_duration

The duration (in seconds) of data acquisition.

sampling_rate

The sampling rate (in Hz) of the analog data acquisition.

trigger()

Return the acquired data.

If the acquisition is not finished by the time this method is called, it will first wait until finished (blocking other processing) and then return the data.

Trigger

class pphelper.hardware.Trigger(ni_lines=u'Dev1/PFI2:9', ni_start_trigger_line=None, ni_task_name=u'Triggers', use_threads=False, test_mode=False)

Bases: pphelper.hardware._StimulationApparatus

Send triggers, e.g. to the EEG system.

Parameters:
  • ni_lines (string, optional) – The lines of the NI board to use as output channel. Defaults to Dev1/PFI2:9.
  • ni_start_trigger_line (str or None, optional) – If specified, start the generation only after a start trigger (high voltage) on this digital line has been received. If None, no external trigger is required.
  • ni_task_name (string, optional) – The name of the NI DAQ task to create. Defaults to Triggers.
  • use_threads (bool, optional) – Whether a Python thread should be created when select_stimulus is called. This thread would then allow non-blocking stimulation. Defaults to False.
  • test_mode (bool, optional) – If True, the NI board will not actually be initialized or used in any manner. This allows for testing the program logic on a computer without a DAQ card. Defaults to False.
add_stimulus(*args, **kwargs)
add_trigger(name, trig_num, duration=None, trigger_time=None, replace=False, **kwargs)

Add a stimulus to the stimulus set of this apparatus.

Parameters:
  • name (string) – A unique identifier of the stimulus to add.
  • trig_num (int) – The trigger to send.
  • duration (float or None, optional) – The duration of the trigger HIGH voltage, specified in seconds. Defaults to 0.001 second. If None, the trigger line is left in the HIGH state.
  • trigger_time (float, optional) – The time (in terms of the psychopy.core.getTime timebase) at which the stimulation should be triggered. If None, trigger immediately. Defaults to None.
  • replace (bool, optional) – Whether an already existing stimulus of the same name should be replaced or not. Defaults to False.

Notes

Any additional keyword arguments will be added as additional stimulus properties.

remove_stimulus(name)

Remove the specified stimulus, identified by its unique name, from the stimulus list.

Parameters:name (string) – The unique name of the stimulus to remove.
remove_trigger(name)
select_stimulus(name)
select_trigger(name)

Select the specified trigger for the next generation.

Parameters:name (string) – The unique name of the trigger to select.
stimulate(blocking_wait=False)

Start the generation of the currently selected trigger.

Parameters:blocking_wait (bool, optional) – Specifies whether the trigger thread should be joined or not, i.e. whether we should wait for it to finish (blocking other operations), or return immediately. This parameter will be ignored if threads are not used for stimulation. Defaults to False, i.e. non-blocking behavior.

Notes

trigger invokes _trigger, which itself unsets the currently selected trigger at the end of the generation. You have to invoke select_trigger again before you can call trigger again.

stimuli

A list of all stimuli added to this stimulation apparatus.

stimulus

The currently selected stimulus.

This stimulus will be presented when invoking stimulate. It can be set using select_stimulus.

test_mode
trigger(blocking_wait=False)

EEG (PyCorder)

class pphelper.hardware.EEG(exp_name, participant, config_file, pycorder_host=u'758098-G-PC', pycorder_port=6700, test_mode=False)

Bases: object

Provides a remote-control interface to PyCorder.

Parameters:
  • exp_name (str) – Name of the experiment. Will make up the first part of the EEG filename.
  • participant (str) – Participant identifier. Will make up the second part of the EEG filename.
  • config_file (str) – The full path to the configuration file, with forward slashes as path separators.
  • pycorder_host (string, optional) – The IP address or hostname of the computer running PyCorder. Defaults to 758098-G-PC.
  • pycorder_port (int, optional) – The port on which PyCorder is listening for a connection on the EEG computer. This should usually not need to be changed. Defaults to 6700.
  • test_mode (bool, optional) – If True, the network connection to the PyCorder computer will not actually be initialized. Defaults to False.
set_block(block)

Set the number of the current block.

This number will make up the last part of the EEG filename.

Parameters:block (int, or string) – The block number, e.g., 1 or 2.
set_config_file(path)

Set the path to the configuration file. An absolute path is required.

Parameters:path (string) – The path to the configuration file, e.g., ‘C:UsersEEGDesktopExperimentconfig.xml’.
set_exp_name(name)

Set the name of the experiment or study.

The name will make up the first part of the EEG filename.

Parameters:path (string) – The name of the study or experiment, e.g., ‘MyStudy2’.
set_mode(mode)

Set the current mode.

Parameters:mode (string) – The mode to switch to. impedance and imp will switch to impedance mode, while monitoring and mon will switch to monitoring mode. default and `def will exit impedance and monitoring mode.
set_participant(participant)

Set the participant identifier.

This identifier will make up the center part of the EEG filename.

Parameters:participant (int or string) – The participant identifier, e.g., 123.
start_recording()

Start recording EEG.

stop_recording()

Stop recording EEG.