Nilearn “These spheres are empty:” error question

Hello all,

I am currently running a searchlight analysis using Nilearn (with 5 mm radius) and using SPM First level beta maps as input. While fitting my searchlight, I am getting the error; “These Spheres are empty: [list of spheres]” for some subjects which seems to be traced to nilearn/maskers/

I saw someone else asked this question and their problem was solved but the user does not share how:

How to handle “These spheres are empty:” error?

Could anyone give me some advice on how I could solve this issue?


Hi @Merve, can you provide code so that we can reproduce the error, preferably with Nilearn data and/or open data you can point us to?

Sure; here is a snippet:

dataset = GetData(tasks=args.tasks, labels={"_f_": 1, "_nf_": 2}, group_filter=runs)
data = dataset(args.data_dir)

SL = nilearn.decoding.SearchLight(
    )["data"], data["labels"], data["groups"])
    scores = SL.scores_
    output = join(
        (f"sub-{args.subj}_{args.filename}_" f"radius_{int(args.radius)}"),

GetData is a self made class that returns a dictionary with the data files, labels and groups. Mask is the brain mask corresponding to the subject, radius is 5mm, estimator is lda, and cv is LeaveOneGroupOut().

Couple of questions

You say:

So this is not a systematic error?

The mask you are using is the brain mask created by SPM during the GLM?

I obtained the masks during fMRIprep preprocessing. I think this might have caused the issue. Initially I did everything from the bids conversion with heudiconv, then preprocessing with fMRIprep and then GLM with Nilearn. However, the previous researcher who acquired the data had “better” SPM (they had done preprocessing on SPM as well) first level results, so I ended up using their first level beta maps but kept the brain mask as my preprocessing derivatives. I carried out the preprocessing basically the way they did it on SPM but I will check now with the SPM mask.

Worth a double check indeed: SPM usually only runs the GLM on a subset of voxels and gives you a binary mask to tell you what voxels were included. It may very well be that the fmriprep mask and the SPM mask do not match. So it could be that for some points of your searchlight, there is no value because SPM did not estimate the GLM there.

FYI: there is a way to change the threshold SPM uses to include voxels in the GLM and also to pass it a mask to force it to run the GLM in. So if you wanted to only use the fmriprep mask, it can be done.

@Remi-Gau you were right! The masks did not match, now I have done everything using the SPM masks and everything worked fine. Thank you so much!

1 Like

I am glad I could help.