Questions about adding a custom standard template

I am using fmriprep1.4.0 and trying to use a pediatric template for my toddler data preprocessing. The --output-spaces option allows for providing paths to custom templates that follow TemplateFlow’s naming conventions (e.g., /path/to/custom/templates/tpl-MyCustom:res-2). As I understand, the template should be in BIDS format with a corresponding .json file. However, the toddler template I am using is in NIFTI format already ( Is there a way to convert it to BIDS format and generate .json file simultaneously? If I provide the path to the template in --output-spaces option, would this template be used throughout the preprocessing? What would be the voxel size of preprocessed images? Would it be the same as the voxel size of the template?

Thank you very much.


Hi @Yaqiong,

We are trying to add that particular template to TemplateFlow (and hence, fMRIPrep). At this point, fMRIPrep can’t read custom templates (everything is in place to allow it, but we still need a little bit of coding).

Since reading the template to provide it as custom and adding it to TemplateFlow would be equivalent, would you like to add it directly to TemplateFlow?

Hi @oesteban, thanks for your response. Glad to know this function is almost there. I am not quite sure how to add it directly to TemplateFlow, if I have the template folder (in a similar format as one here: Could you walk me through it? Thank you.

I think the bottleneck is just organizing the files and writing the metadata. Once that is done, it is fairly easy for me to upload the template.

Great. I am also working on a cohort of child fMRI data and hoping to use an age-matched pediatric template (; 7.5-13.5 years) or Haskins pediatric template (7-12 years) in AFNI. Could you please also upload these two templates to the TemplateFlow? It would be great if you can keep me updated when these templates are ready to use.

Thank you.

Hi @oesteban, just wanted to follow up on the topic of adding the pediatric templates to TemplateFlow. Are there any updates?
Thank you.

Hi @Yaqiong,

Could you try the new pediatric templates of TemplateFlow? We are testing this new feature on fMRIPrep version 1.4.1rc2

In principle, it should be as easy as adding the following arguments:

--skull-strip-template MNIInfant:cohort-3 --output-spaces MNIInfant:cohort-3:res-2 <other-spaces>

Please replace MNIInfant with MNIPediatricAsym if those fit better your age range (MNIInfant is 0-4.5yr and MNIPediatricAsym goes from 4.5yo through 18yo).

Please replace cohort-3 with the age range that better approximates your application (MNIInfant, MNIPediatricAsym)

Hi @oesteban,

Thank you very much for the updates. I have tried the new pediatric template of Template Flow using the command that you provided but ran into some errors (see below). I have several questions regarding the errors. First, I have specified output --output-spaces MNIInfant:cohort-9:res-2, but why did it download tpl-MNIInfant_cohort-9_res-1_T1w.nii.gz instead? Second, for Freesurfer, how can I specify the output space (default fsaverage5")? Third, how to add the output space for --use-aroma? It is not using the one I specified but using “MNI152NLin6Asym:res-2” instead. Thanks.

The whole command I am using is as following:
singularity run
–home /scratch/YX_data_analysis:/asd/apps/software
/asd/apps/software/Converted_BIDs /asd/apps/software/RESTvsTASK participant
–participant-label ${subj}
–skull-strip-template MNIInfant:cohort-9 --output-spaces MNIInfant:cohort-9:res-2
–use-aroma --output-spaces MNIInfant:cohort-9:res-2
–nthreads 6 --n_cpus 12 --omp-nthreads 12
–mem-mb 16000
–fs-license-file /asd/apps/software/license.txt I have several questions for that

Error report:
Although --fs-no-reconall was not set (i.e., FreeSurfer is to be run), no FreeSurfer output space (valid values are: fsaverage, fsaverage6, fsnative, fsaverage5) was selected. Adding default “fsaverage5” to the list of output spaces.
Option “–use-aroma” requires functional images to be resampled to MNI152NLin6Asym space. The argument “MNI152NLin6Asym:res-2” has been automatically added to the list of output spaces (option --output-spaces).
190609-07:50:42,606 nipype.workflow IMPORTANT:

Running fMRIPREP version 1.4.1rc2:
  * BIDS dataset path: /asd/apps/software/Converted_BIDs.
  * Participant list: ['AACE54614A'].
  * Run identifier: 20190609-075042_f3cd8a79-11cf-4049-8d45-919c48a89aeb.

Process Process-2:
Traceback (most recent call last):
File “/usr/local/miniconda/lib/python3.7/multiprocessing/”, line 297, in _bootstrap
File “/usr/local/miniconda/lib/python3.7/multiprocessing/”, line 99, in run
self._target(*self._args, **self._kwargs)
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/cli/”, line 608, in build_workflow
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/workflows/”, line 259, in init_fmriprep_wf
File “/usr/local/miniconda/lib/python3.7/site-packages/fmriprep/workflows/”, line 551, in init_single_subject_wf
File “/usr/local/miniconda/lib/python3.7/site-packages/smriprep/workflows/”, line 230, in init_anat_preproc_wf
normalization_quality=‘precise’ if not debug else ‘testing’)
File “/usr/local/miniconda/lib/python3.7/site-packages/niworkflows/anat/”, line 188, in init_brain_extraction_wf
tpl_target_path = get_template(in_template, **template_spec)
File “/usr/local/miniconda/lib/python3.7/site-packages/templateflow/”, line 39, in get
File “/usr/local/miniconda/lib/python3.7/site-packages/templateflow/”, line 139, in _s3_get
with‘wb’) as f:
File “/usr/local/miniconda/lib/python3.7/”, line 1176, in open
File “/usr/local/miniconda/lib/python3.7/”, line 1030, in _opener
return, flags, mode)
OSError: [Errno 30] Read-only file system: ‘/opt/templateflow/tpl-MNIInfant/cohort-9/tpl-MNIInfant_cohort-9_res-1_T1w.nii.gz’

We are currently looking into this and some other related issues ATM. Thanks for your patience.

--output-spaces should understand both volumetric and surface outputs - placing fsnative and/or fsaverageX should work out. Please note the ‘s’ at the end of --output-spaces because the command line still accepts the deprecated --output-space argument.

ICA-AROMA was trained on MNI152NLin6Asym:res-2 and thus, it can only operate correctly on that space. You could maybe discuss with @mmennes et al. whether it makes sense to also train the noisy components on some infant/pediatric template space. If that happened, we would allow swapping the ICA-AROMA template.

We are currently working on this, simultaneously to Q1.

Thanks very much

Hi @oesteban,

Just wanted to check in with you on the progress of those issues. Any updates?
Thank you very much for helping with that.

I’ll address the questions that remain open:

After reflecting on this, the resolution 1 is used for spatial normalization as target. Then res-2 is used as reference during resampling. Therefore that should be the regular behavior.

This should be fixed with version 1.4.1rc4. You may require some tunning of your singularity run command line to make sure templateflow has access to a writable directory. But, if your singularity installation automatically binds $HOME, it should work out of the box.

Hi @oesteban,

Thanks for the updates. I am now running the processing with 1.4.1rc4, and it is working so far. Though, I still have one follow-up question for you.

For Freesurfer, there are several options for the output space, including fsnative, fsaverage,fsaverage6, and fsaverage5. As I understand, fsnative is in the subject’s native space and the others are in MNI space, right? What is the difference between fsaverage6 and fsaverage5? In my case (toddler data), should I use fsnative instead?

Thank you very much.

Those are purely FreeSurfer’s outputs. That means you’ll find documentation about them in their website.

fsaverage, fsaverage6 and fsaverage5 are effectively in FS’ internal flavor of MNI305, after surface alignment to their average template.

The different fsaverage flavors are explained in this thread It boils down to the density of sampling the surface.

Unless your study design requires you to work on surfaces, I’d say I would keep the analysis in the volume (and thus, no need for any fsX outputs). But this is not a question of the appropriateness of the outputs, is more about your analysis design.

Dear all,

I was wondering if there was any update about the possibility of adding a custom template to the fmriprep pipeline.

I work with old-subjects populations and would like to use an age-specific template such as the MCALT:
I have already prepared a folder with the related files in ‘templateflow’ format.

Thank you very much for any input :slight_smile:

1 Like


We have successfully added a custom template. We used the filename conventions for OASIS ( and created the other derived outputs (tissue probability, masks, etc.). Then we placed the template in ~/.cache/templateflow/tpl-CUSTOMNAME and ran fmriprep. The only tricky part was getting things at a lower resolution, for which we just resampled three files of the template to 2mm and called them res-02.

If you are going this route, I suggest you specify exactly where are you stuck. In principle if you create the same files existing in another template you should be fine.

1 Like

Hi there, I am using two different templates (young and old) but they are in .nii.gz format. I understand that to add them to fmriprep they must be in BIDS format? How do I achieve this? Thanks!

1 Like