AFNI pRF with 3dNLfim

Dear AFNI wizards,

I’m trying to run a population receptive field (PRF) analysis with AFNI but I’m new to the software package and generally still a bit confused. I was hoping somebody could give me a hint as to whether I go wrong at some point.

First, I try to create a stimulus BRIK. The experiment involved a sweeping bar stimulus of which I have the image files (binary masks 990x990) as png files. Given the onset and duration of the bar sweeps, I convert them to a series of jpg files (one for each TR). Then, I create a stimulus brik from it like so:

3dTcat -prefix stim.360 -TR 1.5 mask*.jpg
3drefit -orient LSA stim.360+orig

# convert to nifti for use in fsl
3dAFNItoNIFTI stim.360+orig. stim.360.nii.gz 
# threshold and binarize stimulus nifti
fslmaths stim.360.nii -thr 100 tmp.nii
fslmaths tmp.nii.gz -bin tmp_bin.nii
# back to brick
3dcopy tmp_bin.nii.gz stim_bin+orig.

Next, I try to create a convolution reference time series (I think it should be a simple canonical HRF)

3dDeconvolve -nodata 18 1.5 -polort -1 \
  -num_stimts 1 -stim_times 1 '1D:0' SPMG1 \
  -x1D conv.ref.spmg1.1D

Then, I try to prepare the data. The basis is file called data.nii.gz, which is just the average of detrended time series from four runs with same experiment.

make a copy in AFNI format

3dcopy data.nii.gz AFNIpRF+orig.

calculate the mean for each voxel

3dTstat -mean -prefix AFNIpRFMean AFNIpRF+orig. -overwrite

Calculate a brain mask

3dAutomask -prefix automask AFNIpRF+orig. -overwrite

Demean and scale the time-series data

3dcalc -a AFNIpRF+orig. -b AFNIpRFMean+orig. -c automask+orig. -expr ‘100c(a-b)/b’ -prefix e.scale.demean+orig. -overwrite

The enviroment variables are set like so





Finally, I run 3dnlfim

3dNLfim -input e.scale.demean+orig. \
  -mask automask+orig. \
  -noise Zero \
  -signal Conv_PRF \
  -sconstr 0 -10.0 10.0 \
  -sconstr 1 -1.0 1.0 \
  -sconstr 2 -1.0 1.0 \
  -sconstr 3 0.0 1.0 \
  -BOTH \
  -nrand 10000 \
  -nbest 5 \
  -bucket 0 Buck.PRF \
  -snfit snfit.PRF \
  -TR 1.5 \

# convert to nifti for compatibility later
3dAFNItoNIFTI Buck.PRF+orig. buck.nii.gz
3dAFNItoNIFTI snfit.PRF+orig. snfit.nii.gz

AFNI seems to run the fit (for a little less than 30 minutes). However, when I look at the output Buck.PRF, I can’t make sense of it. It seems a bit random. (see attached file).

Does anybody know, at what point I’m failing? Or am I not interpreting the output correctly?

Again, I’m really new to AFNI and any hints would be very welcome.


Hi Oliver,

There should be many volumes in the Buck.PRF dataset. Note that buck.nii.gz is not technically valid NIFTI because it has many different stat types, so it is possible you would want to break it apart for other software.

In any case, that dataset has many volumes, one for each parameter, plus statistics. It might be good to watch a video on viewing statistical results, such as:

Also, maybe review the help for that PRF model function, which is not obvious how to see:


Maybe the output volumes are not so well described, but note that the purpose of the program is to find model parameters at every voxel, plus statistics for significance.

Would you like more details on the output? Running “3dinfo -VERB” on the output dataset might be helpful, too.

  • rick