pred_brain.exp.pupil_labs#
Connect to, configure, and interact with Pupil Labs eye trackers.
- pred_brain.exp.pupil_labs.get_pupil_labs_device(search_duration_seconds: float = 3.0, n_offset_measurements: int = 100)#
Connect to a Pupil Labs eye tracker and estimate its clock offset.
The user is first asked whether to connect to an eye tracker. If the user declines, the function returns
(None, None).If the user chooses to connect, the function searches the network for available devices. A single device is selected automatically. If multiple devices are discovered, the user selects one by its IP address.
If no device is discovered, the user can return to the initial configuration dialog and try again. Cancelling any dialog terminates the PsychoPy experiment.
- Parameters:
- search_duration_secondsfloat, default=3.0
Number of seconds to search the network for Pupil Labs devices.
- n_offset_measurementsint, default=100
Number of measurements used to estimate the clock offset between the computer and the selected device.
- Returns:
- deviceDevice or None
The connected Pupil Labs device, or
Noneif the user chooses not to connect to one.- median_offset_nsint or None
The median estimated clock offset, in nanoseconds, or
Noneif no device is used.
- pred_brain.exp.pupil_labs.configure_pupil_labs_template(device: Device | None, template_name: str, template_data: dict | None = None, verify_or_post: str = 'verify')#
Verify the active template and optionally verify or update its data.
If another template is active, the user is prompted to select the requested template and retry. When
template_datais provided, the function either checks its values against the active template or posts them, depending onverify_or_post.- Parameters:
- deviceDevice or None
Connected Pupil Labs device. If
None, the function does nothing.- template_namestr
Name of the template to verify.
- template_datadict or None, default=None
Template fields to verify or update. Every key must already exist in the active template data. If
None, no template data is checked or posted.- verify_or_poststr, default=”verify”
"verify"to compare the supplied values with the active template, or"post"to update the active template with those values.
- Raises:
- KeyError
If
template_datacontains a key that is absent from the active template data. The device is closed before the exception is raised.- ValueError
If verification finds values that do not match, or if
verify_or_postis not"verify"or"post". For a verification mismatch, the device is closed before the exception is raised.
Notes
Cancelling the template-selection dialog closes the device and quits PsychoPy. On success, the device remains open; the caller is responsible for closing it when it is no longer needed.
- pred_brain.exp.pupil_labs.send_event_to_pupil_labs(event_string: str, device: Device | None = None, clock_offset_ns: int | None = None) None#
Send a timestamped event to a connected Pupil Labs eye tracker.
The event timestamp is based on the computer’s current Unix time and is adjusted by the estimated clock offset between the computer and the eye tracker. If no device is provided, the function returns without sending an event.
- Parameters:
- event_stringstr
Description or label of the event.
- deviceDevice or None, default=None
Connected Pupil Labs device. If
None, no event is sent.- clock_offset_nsint or None, default=None
Estimated clock offset, in nanoseconds, to subtract from the computer’s Unix timestamp. If
None, no event is sent.