View on GitHub


A population receptive field estimation tool

Download this project as a .zip file Download this project as a tar.gz file

What is a population receptive field?

A population receptive field (pRF) is a quantitative model of the cumulative response of the population of cells contained within a single fMRI voxel [1]. The pRF model allows us to interpret and predict the responses of a voxel to different stimuli. Such models can be designed to describe various sensory [2] and cognitive processes [3]. More recently, the pRF model has been used to map the retinotopic organization of multiple subcortical nuclei [4].


Download the popeye source code from the GitHub repository. Links to the tarball and zip files are at the top of this page for your convenience. Using popeye requires that you have installed NumPy, SciPy, statsmodel, Cython, and nibabel. Installing matplotlib is recommended as we'll be plotting the results of our pRF estimation but is not required for any of the model fitting procedures in popeye.

Once you've downloaded the popeye source code and installed the aforementioned dependencies, you'll need to install popeye and build the Cython extensions I've written for speeding up the analyses.

$ cd popeye
$ sudo python install build_ext
$ cd ~
$ python
>>> import popeye
>>> popeye.__version__


The code below is meant to provide only a small preview of the purpose and organization of popeye. The full documentation for popeye is available here.

Getting started

Below is a small demonstration of how to interact with the popeye API. Here, we'll generate our stimulus and simulate the BOLD response of a Gaussian pRF model estimate we'll just invent. Normally, we'd be analyzing the BOLD time-series that we collect while we present a participant with a visual stimulus.

import ctypes, multiprocessing
import numpy as np
import popeye.og as og
import popeye.utilities as utils
from popeye.visual_stimulus import VisualStimulus, simulate_bar_stimulus

## create sweeping bar stimulus
sweeps = np.array([-1,0,90,180,270,-1]) # in degrees, -1 is blank
bar = simulate_bar_stimulus(100, 100, 40, 20, sweeps, 30, 30, 10)
## create an instance of the Stimulus class
stimulus = VisualStimulus(bar, 50, 25, 0.50, 1.0, ctypes.c_int16)
## initialize the gaussian model
model = og.GaussianModel(stimulus, utils.double_gamma_hrf)

## generate a random pRF estimate
x = -5.24
y = 2.58
sigma = 1.24
beta = 1
hrf_delay = -0.25

## create the time-series for the invented pRF estimate
data = model.generate_prediction(x, y, sigma, beta, hrf_delay)

## add in some noise
data += np.random.uniform(-data.max()/10,data.max()/10,len(data))

### FIT
## define search grids
# these define min and max of the edge of the initial brute-force search. 
x_grid = (-10,10)
y_grid = (-10,10)
s_grid = (0.25,5.25)
b_grid = (0.01,1.0)
h_grid = (-4.0,4.0)

## define search bounds
# these define the boundaries of the final gradient-descent search.
x_bound = (-12.0,12.0)
y_bound = (-12.0,12.0)
s_bound = (0.001,12.0)
b_bound = (1e-8,1e2)
h_bound = (-5.0,5.0)

## package the grids and bounds
grids = (x_grid, y_grid, s_grid, b_grid, h_grid)
bounds = (x_bound, y_bound, s_bound, b_bound, h_bound)

## fit the response
# auto_fit = True fits the model on assignment
# verbose = 0 is silent
# verbose = 1 is a single print
# verbose = 2 is very verbose
fit = og.GaussianFit(model, data, grids, bounds, Ns=3, 
                     voxel_index=(1,2,3), auto_fit=True,verbose=2)

## plot the results
import matplotlib.pyplot as plt

## multiprocess 3 voxels
data = [data,data,data]
indices = ([1,2,3],[4,6,5],[7,8,9])
bundle = utils.multiprocess_bundle(og.GaussianFit, model, data, 
                                   grids, bounds, 3, indices, True, 1)

## run analysis
pool = multiprocessing.Pool(3)
output =, bundle)

Below is the output of the model fit we invoked in the code block above. Explore the attributes of the fit object to get a sense of the kinds of measures we've gleaned from the model.


popeye was created by Kevin DeSimone (@kdesimone) with significant contributions and guidance from Ariel Rokem (@arokem).


Having trouble with popeye? Contact


[1] Dumoulin SO, Wandell BA (2008) Population receptive field estimates in human visual cortex. NeuroImage 39:647-660.

[2] Thomas JM, Huber E, Stecker E, Boynton G, Saenz M, Fine I (2014) Population receptive field estimates in human auditory cortex. NeuroImage 109: 428:439.

[3] Harvey BM, Klein BP, Petridou N, Dumoulin SO (2013) Topographic organization of numerosity in the human parietal cortex. Science 341: 1123-1126.

[4] DeSimone K, Viviano JD, Schneider KA (2015) Population receptive field estimation reveals two new maps in human subcortex. Journal of Neuroscience 35: 9836-9847.