Skip to main content

A PsychoPy extension for stereoscopic display and more.

Project description

Introduction

The psykit package extends the capacity of the PsychoPy package in generating stereoscopic stimuli, using offscreen windows, and more.

  • PsychoPy is a great tool for quickly creating psychophysical experiments. However, it has limited support for stereoscopic displays out-of-the-box. The psykit.stereomode module provides the StereoWindow class, a drop-in upgrade for psychopy.visual.Window, which supports a wide variety of stereo modes similar to Psychtoolbox in Matlab, including

    • ‘left/right’ (for prisms and mirrors)

    • ‘side-by-side-compressed’ (for some VR goggles)

    • ‘dual-head’ (for some VR goggles with two video inputs)

    • ‘red/blue’ (for anaglyph glasses)

    • ‘sequential’ (for blue line sync shutters)

    • ‘top/bottom’ (for the double-height mode of ProPixx projector)

    • ‘top/bottom-anticross’ (same as above but with cross-talk compensation)

    Users can debug in one stereo mode and do experiment in another, without needing to modify their code. Most modes can even be switched back and forth at runtime.

  • Sometimes, we need to dynamically render a complex scene and reuse it for multiple times, e.g., drawing a dynamic and complex background for both left- and right-eye buffers. The psychopy.visual.BufferImageStim is not suitable in this case because it is fast to draw but slower to init. The psykit.offscreen module provides the OffscreenWindow class, essentially a framebuffer designed for drawing various stimuli efficiently. These can then be rendered collectively at high speed. Unlike BufferImageStim, OffscreenWindow is fast to draw and fast to init, and may significantly reduce rendering time and the risk of frame drops in the above use case.

  • PsychoPy users who come from Psychtoolbox sometimes miss the flexibility of the Screen('DrawTexture') style low-level API, e.g., for drawing only part of a texture. The psykit package implements some of these low-level functions like psykit.create_texture and psykit.draw_texture for special use cases. See this example for an interesting demo.

  • The psykit.gltools module provides an alternative and lightweight wrapper (compared to psychopy.tools.gltools) around modern OpenGL commands, e.g., shader, VAO, FBO, etc., which are used by other modules.

  • The psykit.pupillabs module provides utilities to work with pupil-labs eye-trackers like the Neon.

  • The psykit/demos folder contains many example scripts demonstrating our favorite use cases, e.g., how to use psykit.stereomode.StereoWindow with psychopy, as well as various 3D modes of the ProPixx projector.

Documentation

The basic usage is intuitive:

from psychopy import visual, event, core
from psykit import StereoWindow # from psykit.stereomode import StereoWindow

# Open a stereo window
win = StereoWindow(monitor='testMonitor', units='deg', fullscr=False,
    stereoMode='top/bottom-anticross', crossTalk=[0.07,0.07], color='gray')
gabor = visual.GratingStim(win, tex='sin', mask='gauss', size=[5,5], sf=1)
t = win.flip()
while True:
    # Draw left eye stimuli
    win.setBuffer('left')
    gabor.phase = 3*t
    gabor.draw()
    # Draw right eye stimuli
    win.setBuffer('right')
    gabor.phase = 2*t
    gabor.draw()
    # Flip
    t = win.flip()
    if 'escape' in event.getKeys():
        break
win.close()
core.quit()

For Builder users, it is easy to adapt an ordinary Window into a StereoWindow:

# Open an ordinary window (e.g., from the Builder)
win = visual.Window(monitor='testMonitor', units='deg', fullscr=False, color='gray')
# Adapt it into a stereo window
win = StereoWindow(win, stereoMode='top/bottom-anticross', crossTalk=[0.07,0.07])

To use an OffscreenWindow as a drawing buffer to cache and reuse intermediate drawing results:

from psykit import OffscreenWindow # from psykit.offscreen import OffscreenWindow

buffer = OffscreenWindow(win) # Create an offscreen window
buffer.bind() # Bind the offscreen window's framebuffer to redirect drawings
draw_many_stims()
buffer.unbind() # After unbinding, subsequent drawings go back to default screen
# Draw left eye stimuli
win.setBuffer('left')
buffer.draw() # Draw the content of the offscreen window as a texture
# Draw right eye stimuli
win.setBuffer('right')
buffer.draw() # Draw again and save some time

You may also find the following demo stripts useful:

  • demos/minimum_example.py # A minimum quickstart script that uses StereoWindow

  • demos/stereo_modes.py # Switch between modes at runtime and adjust cross-talk compensation

  • demos/dualhead_mode.py # Use ‘dual-head’ mode to draw two eye’s views in two physical screens

  • demos/visual_stims.py # Draw various stimuli (e.g., Aperture) in StereoWindow

  • demos/adjust_fixation.py # Adjust vergence and coordinate origin for ‘left/right’ mode

  • demos/propixx_polarizer.py # Work with different 3D modes of ProPixx projector

  • demos/offscreen_window.py # Use OffscreenWindow to cache and reuse complex stimuli

  • demos/draw_texture.py # Use draw_texture to only draw a selected part of a texture

Installation

The most convenient way to install psykit is via the “Plugin/packages manager” of Psychopy GUI interface. After opening the “Plugins & Packages” dialog, go to the “Packages” tab, click “Open PIP terminal”, execute “pip install psykit”. If you want to upgrade an existing installation, execute “pip install -U psykit”.

If you installed PsychoPy via the standalone installer, it is also possible to download and unzip the psykit source code and copy the package folder into the applicaton folder:

  • For macOS: “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psykit”

  • For Windows: “C:\Program Files\PsychoPy\Lib\site-packages\psykit”

Otherwise, simply use pip install:

pip install psykit

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psykit-1.2.8.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psykit-1.2.8-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

Details for the file psykit-1.2.8.tar.gz.

File metadata

  • Download URL: psykit-1.2.8.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for psykit-1.2.8.tar.gz
Algorithm Hash digest
SHA256 629d665dcc4dd877df3bed6503c46ad1723b715e4785b2fba4f420ead3cefc49
MD5 de4704b7b4071a824c9b0c326552b8e8
BLAKE2b-256 ed633b97977973880bc6109d62245669f37e447e6e483341423ec42e9bd0dd60

See more details on using hashes here.

File details

Details for the file psykit-1.2.8-py3-none-any.whl.

File metadata

  • Download URL: psykit-1.2.8-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for psykit-1.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1e9ff506313ea38d477f65a443755f12ef9dfb3acb13de01a37aacaf0158ad61
MD5 fa285f0f49a83f572850f4e2fb5333e9
BLAKE2b-256 b314cb67e2301ccf3fe6d9c050d7456347703adf7ae57d15ebe9c0e8b8cc21e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page