Load_confounds not recognizing the confounds file

Summary of what happened:

I am attempting to use nilearn.interfaces.fmriprep.load_confounds to apply global signal regression (GSR) to my data. My data was processed in fmriprep using AROMA. Here is the exact app that I used to process the data: app-fmriprep. My data was processed on Brainlife and then saved locally, so my files are no longer named according to the fmriprep conventions, but I did my best to BIDS-ify them.

This is an example of what the data looks like:

The ica-aroma files are in their own subfolder because I am not using them currently. Or at least, I am trying not to use them currently.

Command used (and if a helper script was used, a link to the helper script or the command generated):

The rest of my code processes and extracts values from the timeseries. Without this section, the code runs just fine.

confounds_gsr, mask_gsr = load_confounds(

cleaned_epi_path is the path to the bold file.


Python 3.10.9. Nilearn 0.10.0.

Environment (Docker, Singularity, custom installation):

Locally on Ubuntu server

Relevant log outputs (up to 20 lines):

Traceback (most recent call last):
  File "removed-this-string-for-security-reasons.py", line 21, in <module>
    confounds_gsr, mask_gsr = load_confounds(
  File "/home/evb32/.local/lib/python3.10/site-packages/nilearn/interfaces/fmriprep/load_confounds.py", line 275, in load_confounds
    sample_mask, conf = _load_confounds_for_single_image_file(
  File "/home/evb32/.local/lib/python3.10/site-packages/nilearn/interfaces/fmriprep/load_confounds.py", line 304, in _load_confounds_for_single_image_file
    confounds_file = _get_confounds_file(image_file,
  File "/home/evb32/.local/lib/python3.10/site-packages/nilearn/interfaces/fmriprep/load_confounds_utils.py", line 121, in _get_confounds_file
    _check_images(image_file, flag_full_aroma)
  File "/home/evb32/.local/lib/python3.10/site-packages/nilearn/interfaces/fmriprep/load_confounds_utils.py", line 207, in _check_images
    raise ValueError(error_message)
ValueError: Invalid file type for the selected method.

I can see where the error is coming from (here) but I can’t figure out what is wrong with my data. The confounds files seem to be formatted correctly. The bold files look normal.

Screenshots / relevant information:

Things I have tried that did not work:

  • adding aroma to the pipeline
  • renaming the bold file to contain desc-smoothAROMAnonaggr_bold
  • renaming the ica-aroma folder
  • renaming the timeseries files from regressors.tsv and regressors.json to their current names
  • trying every available option for global_signal (“basic”, “full”, etc)

Hi @vnbcs,

There are several errors that make your data not BIDS valid. I would not expect this Nilearn interface to work with non-BIDS fmriprep outputs. One thing you can try is to add the desc-preproc label to your bold file. If that doesn’t work, I would say your best bet is to just load confounds manually (e.g. using Pandas to read the confounds file and indexing just the confounds you want).


Thank you! Is there a way to load the confounds manually and still have nilearn do the GSR? Or are you suggesting I just do the GSR by hand?

Yes, you would just make sure that whatever confounds matrix you pass in to your model has the values from the global signal column.

Out of curiosiy: how come that the files do not have the typical fmriprep filenaming? Is that something happening on the brainlife side?

Yes, Brainlife renames all file outputs. Brainlife has a limited number of “datatypes” that function as input/output to all Brainlife apps (you can see all the datatypes here). A BOLD fMRI can be part of a couple different datatypes, but the nifti file itself is always named bold.nii.gz. Consistent file naming enables the output to be fed into different apps, which is super useful if you’re doing 100% of your processing on Brainlife! But a little annoying for my case. Once I streamline my timeseries pipeline I might turn it into a Brainlife app so I don’t have to deal with downloading and renaming data.

I see.

Once again, deviating from typical BIDS filenaming quickly puts you in a world of pain: sorry about that.

not sure it helps much, but fmriprep AFAIK tries to keep in synch with the draft BIDS extension for functional derivatives that you can find here: