Calibration problem with pupil_labs

Hi there

OS Win10
PsychoPy version 2021.1.
Standard Standalone? Y
What are you trying to achieve?: experiment with pupil-labs

What did you try to make it work?: simple calibration

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2022.1.1),
    on February 24, 2022, at 16:50
If you publish work using this script the most relevant publication is:

    Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019) 
        PsychoPy2: Experiments in behavior made easy Behav Res 51: 195. 
        https://doi.org/10.3758/s13428-018-01193-y

"""

from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout, iohub, hardware
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)

import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle, choice as randchoice
import os  # handy system and path functions
import sys  # to get file system encoding

import psychopy.iohub as io
from psychopy.hardware import keyboard



# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)
# Store info about the experiment session
psychopyVersion = '2022.1.1'
expName = 'untitled'  # from the Builder filename that created this script
expInfo = {'participant': '', 'session': '001'}
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
if dlg.OK == False:
    core.quit()  # user pressed cancel
expInfo['date'] = data.getDateStr()  # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion

# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])

# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
    extraInfo=expInfo, runtimeInfo=None,
    originPath='C:\\Users\\Kid\\Desktop\\DBSL\\our-brainwaves-codes\\Expriment_EmotivX\\temp\\untitled.py',
    savePickle=True, saveWideText=True,
    dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING)  # this outputs to the screen, not a file

endExpNow = False  # flag for 'escape' or other condition => quit the exp
frameTolerance = 0.001  # how close to onset before 'same' frame

# Start Code - component code to be run after the window creation

# Setup the Window
win = visual.Window(
    size=[1280, 720], fullscr=True, screen=0, 
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True, 
    units='height')
# store frame rate of monitor if we can measure it
expInfo['frameRate'] = win.getActualFrameRate()
if expInfo['frameRate'] != None:
    frameDur = 1.0 / round(expInfo['frameRate'])
else:
    frameDur = 1.0 / 60.0  # could not measure, so guess
# Setup ioHub
ioConfig = {}

# Setup eyetracking
ioConfig['eyetracker.hw.pupil_labs.pupil_core.EyeTracker'] = {
    'name': 'tracker',
    'runtime_settings': {
        'pupillometry_only': False,
        'surface_name': 'psychopy_iohub_surface',
        'gaze_confidence_threshold': 0.6,
        'pupil_remote': {
            'ip_address': '127.0.0.1',
            'port': 50020.0,
            'timeout_ms': 1000.0,
        },
        'pupil_capture_recording': {
            'enabled': True,
            'location': '',
        }
    }
}

# Setup iohub keyboard
ioConfig['Keyboard'] = dict(use_keymap='psychopy')

ioSession = '1'
if 'session' in expInfo:
    ioSession = str(expInfo['session'])
ioServer = io.launchHubServer(window=win, **ioConfig)
eyetracker = ioServer.getDevice('tracker')

# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard(backend='iohub')

# Create some handy timers
globalClock = core.Clock()  # to track the time since experiment started
routineTimer = core.CountdownTimer()  # to track time remaining of each (non-slip) routine 
# define target for calibration
calibrationTarget = visual.TargetStim(win, 
    name='calibrationTarget',
    radius=0.01, fillColor='', borderColor='black', lineWidth=2.0,
    innerRadius=0.0035, innerFillColor='green', innerBorderColor='black', innerLineWidth=2.0,
    colorSpace='rgb', units=None
)
# define parameters for calibration
calibration = hardware.eyetracker.EyetrackerCalibration(win, 
    eyetracker, calibrationTarget,
    units=None, colorSpace='rgb',
    progressMode='time', targetDur=1.5, expandScale=1.5,
    targetLayout='NINE_POINTS', randomisePos=True, textColor='white',
    movementAnimation=True, targetDelay=1.0
)
# run calibration
calibration.run()
# clear any keypresses from during calibration so they don't interfere with the experiment
defaultKeyboard.clearEvents()
# the Routine "calibration" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()

# Flip one final time so any remaining win.callOnFlip() 
# and win.timeOnFlip() tasks get executed before quitting
win.flip()

# these shouldn't be strictly necessary (should auto-save)
thisExp.saveAsWideText(filename+'.csv', delim='auto')
thisExp.saveAsPickle(filename)
logging.flush()
# make sure everything is closed down
if eyetracker:
    eyetracker.setConnectionState(False)
thisExp.abort()  # or data files will save again on exit
win.close()
core.quit()

What specifically went wrong when you tried that?

“module ‘psychopy.iohub.devices.eyetracker.hw.pupil_labs.pupil_core’ has no attribute ‘EyeTracker’”

Generating PsychoPy script...

## Running: C:\Users\Kid\Desktop\DBSL\our-brainwaves-codes\Expriment_EmotivX\temp\untitled_lastrun.py ##
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
Error during device creation ....
_addDeviceView: Error adding class. 
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\server.py", line 708, in createNewMonitoredDevice
    dev_data = self.addDeviceToMonitor(dev_cls_name, dev_conf)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\server.py", line 858, in addDeviceToMonitor
    DeviceClass, dev_cls_name, evt_classes = import_device(dev_mod_pth,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\devices\__init__.py", line 933, in import_device
    device_class = getattr(module, device_class_name)
AttributeError: module 'psychopy.iohub.devices.eyetracker.hw.pupil_labs.pupil_core' has no attribute 'EyeTracker'
Error during device creation ....
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\server.py", line 708, in createNewMonitoredDevice
    dev_data = self.addDeviceToMonitor(dev_cls_name, dev_conf)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\server.py", line 858, in addDeviceToMonitor
    DeviceClass, dev_cls_name, evt_classes = import_device(dev_mod_pth,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\devices\__init__.py", line 933, in import_device
    device_class = getattr(module, device_class_name)
AttributeError: module 'psychopy.iohub.devices.eyetracker.hw.pupil_labs.pupil_core' has no attribute 'EyeTracker'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\server.py", line 642, in _addDevices
    self.createNewMonitoredDevice(dev_cls_name, dev_conf)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\server.py", line 721, in createNewMonitoredDevice
    raise ioHubError('Error during device creation ....')
psychopy.iohub.errors.ioHubError: ioHubError:
Args: ('Error during device creation ....',)

13.4594     WARNING     We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['sounddevice', 'PTB', 'pyo', 'pygame'] (in that order).
1.6698     WARNING     Monitor specification not found. Creating a temporary one...
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\client\__init__.py", line 1072, in _addDeviceView
    dev_import_result = import_device(dev_mod_pth, dev_cls_name)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\iohub\devices\__init__.py", line 933, in import_device
    device_class = getattr(module, device_class_name)
AttributeError: module 'psychopy.iohub.devices.eyetracker.hw.pupil_labs.pupil_core' has no attribute 'EyeTracker'
Traceback (most recent call last):
  File "C:\Users\Kid\Desktop\DBSL\our-brainwaves-codes\Expriment_EmotivX\temp\untitled_lastrun.py", line 130, in <module>
    calibration.run()
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\hardware\eyetracker.py", line 165, in run
    tracker = self.eyetracker.getIOHubDeviceClass(full=True)
AttributeError: 'NoneType' object has no attribute 'getIOHubDeviceClass'
################# Experiment ended with exit code 1 [pid:652] ##################

I found the solution.

I copied all of the files form psychopy github"\psychopy-release\psychopy\iohub\devices\eyetracker\hw\pupil_labs\pupil_core" into the “C:\Program Files\PsychoPy\Lib\site-packages\psychopy\iohub\devices\eyetracker\hw\pupil_labs\pupil_core”

:sparkler: :fireworks: :smile: :smile:

1 Like

Hey Matini :slight_smile:
I am having troubles with collaborate pupil-labs to Psychopy.
Can you please write the steps you were taking and where do I supposed to put the code above?
Thank you !

Hi Nofar,
Sorry for the delay in responding.

Just download GitHub version here:

then copy all of file here:
“\psychopy-release\psychopy\iohub\devices\eyetracker\hw\pupil_labs\pupil_core”

finally past files here:
“C:\Program Files\PsychoPy\Lib\site-packages\psychopy\iohub\devices\eyetracker\hw\pupil_labs\pupil_core”

Hi

it could work also with EyeLink 1000 plus eyetracker?