[PYTHON] Build a comfortable psychological experiment / analysis environment with PsychoPy + Jupyter Notebook

Preface

PsychoPy as a library is very complete and much easier to use than Pyglet, Pygame and Kivy, while PsychoPy as an IDE is subtle with weak completion and debugging.

I used to edit scripts in Vim, but recently I've noticed that PsychoPy works very well with Jupyter.

So, this time I will explain how to use PsychoPy with Jupyter.

Before ..., let's first introduce how useful it is.

gallery

Of course it can be started.

20170213_1.png

Want to Hello World? ... then you can add it later.

20170213_2.png

Oops, I wanted to make black letters on a white background. Close the page with win.close () ... What was the color setting of visual.Window?

20170213_3.jpg

Remake and re-present.

20170213_4.png

... you can create experiments interactively like this.

Environment creation

Installation of Anaconda

Use ** Anaconda ** for later analysis. Click here to install.

There are 2 series and 3 series, but here we will include 3 series [^ 1]. The reason is as follows.

Also, I think it is good to install Miniconda instead of Anaconda. The reason is as follows.

However, be aware that if you use Miniconda, you will need to include the libraries (numpy, pandas, etc.) yourself.

Operation check of Jupyter Notebook

After installing Anaconda, first make sure that Jupyter Notebook starts. Open a terminal (Anaconda Prompt for Win) and do the following:

jupyter notebook

If the browser starts up and localhost: 8888 is displayed automatically, it is successful.

Please do not delete the terminal or Anaconda Prompt opened here while using Jupyter Notebook. If you turn it off, the server will stop. On the contrary, if you do not use it anymore, you can close it.

Install PsychoPy

Open Anaconda Prompt (Windows users should run as administrator) and do the following:

pip install psychopy

After installation, try the following from your notebook:

from psychopy import visual

win = visual.Window()

A window should open.

In case of Windows, NotImplementedError may be displayed. In that case, open Anaconda Prompt again with administrator privileges and open it.

pip install pyglet==1.2

(I'm lowering the version because it doesn't work with version 1.3, which comes in by default).

Supplement

behavior of visual.Window

If you try to drag and drop a screen created with fullscr = False, it may become unresponsive. There is no particular problem, and the stimulus is presented properly, so it is okay to proceed with the experiment creation as it is.

Execution speed measurement

With% time or% timeit.
Please when the stimulus presentation is slow.
When set to% 2, the execution time of the entire block is measured.

20170213_5.png

Cooperation with R

If you want to use R with Jupyter Notebook,

https://irkernel.github.io/installation/

Let's put R referring to. Open R

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
IRkernel::installspec()

If you execute ** paying attention to the following **, it will be automatically linked with Jupyter Notebook.

[Caution (Win)]

If ʻIRKernel :: installspec () `is moss, the following measures may be effective.

[Caution (Mac)]

[^ 1]: This article was also compatible with both 2 series and 3 series until January 2018. Since there is almost no merit to install the 2nd system now, I modified it to introduce only the introduction method of the 3rd system.

Recommended Posts

Build a comfortable psychological experiment / analysis environment with PsychoPy + Jupyter Notebook
Build a data analysis environment with Kedro + MLflow + Github Actions
Add an extension to build a more comfortable Jupyter environment
Build a comfortable development environment with VSCode x Remote Development x Pipenv
I want to use a virtual environment with jupyter notebook!
<Python> Build a dedicated server for Jupyter Notebook data analysis
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
Build IPython Notebook environment with boot2docker
Convenient analysis with Pandas + Jupyter notebook
Build jupyter notebook environment with Visual Studio Code (VS Code) Mac version
Easily build a development environment with Laragon
Build Jupyter Lab (Python) environment with Docker
Build a Fast API environment with docker-compose
[Linux] Build a jenkins environment with Docker
Build a python virtual environment with pyenv
Build a modern Python environment with Neovim
[Linux] Build a Docker environment with Amazon Linux 2
Comfortable Jupyter Lab (Python) analysis environment created with Docker + VSCode + Remote Container
Build a C language development environment with a container
Build a WardPress environment on AWS with pulumi
Analytical environment construction with Docker (jupyter notebook + PostgreSQL)
Data analysis for improving POG 2 ~ Analysis with jupyter notebook ~
Build a python environment with ansible on centos6
[Python] Build a Django development environment with Docker
Create a python3 build environment with Sublime Text3
Try using conda virtual environment with Jupyter Notebook
Build a Django environment with Vagrant in 5 minutes
[Memo] Build a virtual environment with Pyenv + anaconda
Build a virtual environment with pyenv and venv
Build a Django development environment with Doker Toolbox
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Build a Python machine learning environment with a container
Build a python execution environment with VS Code
Build a data analysis environment that links GitHub authentication and Django with JupyterHub
Build a PYNQ environment on Ultra96 V2 and log in to Jupyter Notebook
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Easily prepare a Jupyter Notebook environment with Docker (Tensorflow and Graphviz are also available)
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a python environment for each directory with pyenv-virtualenv
Data analysis environment construction with Python (IPython notebook + Pandas)
Drawing a tree structure with D3.js in Jupyter Notebook
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS
Build a machine learning application development environment with Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Build a basic Data Science environment (Jupyter, Python, R, Julia, standard library) with Docker.
Build a development environment with Poetry Django Docker Pycharm
Build a Django environment for Win10 (with virtual space)
Build a numerical calculation environment with pyenv and miniconda3
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS with anaconda
Are you still using Jupyter Notebook? Enjoy a comfortable Python life with Jupyter Life (.py) with VS Code ?!
Recommendation of Jupyter Notebook, a coding environment for data scientists
Build a Django development environment with Docker! (Docker-compose / Django / postgreSQL / nginx)
Machine learning with Jupyter Notebook in OCI Always Free environment (2019/12/17)
Build Azure Pipelies with Azure DevOps in a Linux self-hosted environment
Build a machine learning scikit-learn environment with VirtualBox and Ubuntu
[Memo] Build a development environment for Django + Nuxt.js with Docker
Build a Go development environment with VS Code's Remote Containers
I want to start a jupyter environment with one command
(Now) Build a GPU Deep Learning environment with GeForce GTX 960
[Django] Build a Django container (Docker) development environment quickly with PyCharm