pyoperant.components module

class pyoperant.components.BaseComponent(name=None, *args, **kwargs)[source]

Bases: object

Base class for physcal component

class pyoperant.components.Hopper(IR, solenoid, max_lag=0.3, inverted=False, *args, **kwargs)[source]

Bases: pyoperant.components.BaseComponent

Class which holds information about a hopper

Parameters:
  • solenoid (hwio.BooleanOutput) – output channel to activate the solenoid & raise the hopper
  • IR (hwio.BooleanInput) – input channel for the IR beam to check if the hopper is up
  • max_lag (float, optional) – time in seconds to wait before checking to make sure the hopper is up (default=0.3)
solenoid

hwio.BooleanOutput

output channel to activate the solenoid & raise the hopper

IR

hwio.BooleanInput

input channel for the IR beam to check if the hopper is up

max_lag

float

time in seconds to wait before checking to make sure the hopper is up

check()[source]

reads the status of solenoid & IR beam, then throws an error if they don’t match

Returns:

True if the hopper is up.

Return type:

bool

Raises:
  • HopperActiveError – The Hopper is up and it shouldn’t be. (The IR beam is tripped, but the solenoid is not active.)
  • HopperInactiveError – The Hopper is down and it shouldn’t be. (The IR beam is not tripped, but the solenoid is active.)
down()[source]

Lowers the hopper.

Returns:True if the hopper drops.
Return type:bool
Raises:HopperWontDropError – The Hopper did not drop.
feed(dur=2.0, error_check=True)[source]

Performs a feed

dur : float, optional
duration of feed in seconds
Returns:

Timestamp of the feed and the feed duration

Return type:

(datetime, float)

Raises:
reward(value=2.0)[source]

wrapper for feed, passes value into dur

up()[source]

Raises the hopper up.

Returns:True if the hopper comes up.
Return type:bool
Raises:HopperWontComeUpError – The Hopper did not raise.
exception pyoperant.components.HopperActiveError[source]

Bases: pyoperant.errors.ComponentError

raised when the hopper is up when it shouldn’t be

exception pyoperant.components.HopperAlreadyUpError[source]

Bases: pyoperant.components.HopperActiveError

raised when the hopper is already up before it goes up

exception pyoperant.components.HopperInactiveError[source]

Bases: pyoperant.errors.ComponentError

raised when the hopper is down when it shouldn’t be

exception pyoperant.components.HopperWontComeUpError[source]

Bases: pyoperant.components.HopperInactiveError

raised when the hopper won’t come up

exception pyoperant.components.HopperWontDropError[source]

Bases: pyoperant.components.HopperActiveError

raised when the hopper won’t drop

class pyoperant.components.HouseLight(light, *args, **kwargs)[source]

Bases: pyoperant.components.BaseComponent

Class which holds information about the house light

light : hwio.BooleanOutput
output channel to turn the light on and off

Methods: on() – off() – timeout(dur) – turns off the house light for ‘dur’ seconds (default=10.0) punish() – calls timeout() for ‘value’ as ‘dur’

off()[source]

Turns the house light off.

Returns:True if successful.
Return type:bool
on()[source]

Turns the house light on.

Returns:True if successful.
Return type:bool
punish(value=10.0)[source]

Calls timeout(dur) with value as dur

timeout(dur=10.0)[source]

Turn off the light for dur seconds

dur : float, optional
The amount of time (in seconds) to turn off the light.
Returns:Timestamp of the timeout and the timeout duration
Return type:(datetime, float)
class pyoperant.components.LEDStripHouseLight(lights, color=[100.0, 100.0, 100.0, 100.0], *args, **kwargs)[source]

Bases: pyoperant.components.BaseComponent

Class which holds information about the RGBW LED Strip PWM house light

light : hwio.PWMOutputs
[R, G, B, W] output channels to turn the light on and off

Methods: on() – off() – set_color() – set the color change_color – sets color and turns on light timeout(dur) – turns off the house light for ‘dur’ seconds (default=10.0) punish() – calls timeout() for ‘value’ as ‘dur’

change_color(color)[source]
off()[source]

Turns the house light off.

Returns:True if successful.
Return type:bool
on()[source]

Turns the house light on.

Returns:True if successful.
Return type:bool
punish(value=10.0)[source]

Calls timeout(dur) with value as dur

set_color(color)[source]
timeout(dur=10.0)[source]

Turn off the light for dur seconds

dur : float, optional
The amount of time (in seconds) to turn off the light.
Returns:Timestamp of the timeout and the timeout duration
Return type:(datetime, float)
class pyoperant.components.PeckPort(IR, LED, inverted=False, *args, **kwargs)[source]

Bases: pyoperant.components.BaseComponent

Class which holds information about peck ports

Parameters:
LED

hwio.BooleanOutput

output channel to activate the LED in the peck port

IR

hwio.BooleanInput

input channel for the IR beam to check for a peck

flash(dur=1.0, isi=0.1)[source]

Flashes the LED on and off with isi seconds high and low for dur seconds, then revert LED to prior state.

Parameters:
  • dur (float, optional) – Duration of the light flash in seconds.
  • isi (float,optional) – Time interval between toggles. (0.5 * period)
Returns:

Timestamp of the flash and the flash duration

Return type:

(datetime, float)

off()[source]

Turns the LED off

Returns:True if successful
Return type:bool
on(val=100.0)[source]

Turns the LED on

Returns:True if successful
Return type:bool
poll(timeout=None)[source]

Polls the peck port until there is a peck

Returns:Timestamp of the IR beam being broken.
Return type:datetime
status()[source]

reads the status of the IR beam

Returns:True if beam is broken
Return type:bool
class pyoperant.components.RGBLight(red, green, blue, *args, **kwargs)[source]

Bases: pyoperant.components.BaseComponent

Class which holds information about an RGB cue light

red : hwio.BooleanOutput
output channel for the red LED
green : hwio.BooleanOutput
output channel for the green LED
blue : hwio.BooleanOutput
output channel for the blue LED
blue()[source]

Turns the cue light to blue

Returns:True if successful.
Return type:bool
green()[source]

Turns the cue light to green

Returns:True if successful.
Return type:bool
off()[source]

Turns the cue light off

Returns:True if successful.
Return type:bool
red()[source]

Turns the cue light to red

Returns:True if successful.
Return type:bool