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/nifti_spheres_masker.py.

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?

Thanks!

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(
        mask_img=args.mask,
        radius=args.radius,
        estimator=args.estimator,
        n_jobs=1,
        verbose=1,
        cv=cv,
        scoring="accuracy",
    )
    SL.fit(data["data"], data["labels"], data["groups"])
    scores = SL.scores_
    output = join(
        f"{args.output_dir}",
        (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.

Hello, I had a same problem by using searchlight analysis using Nilearn.[quote=“Merve, post:1, topic:25295, full:true”]. I am not sure which step is wrong.
I firstly get GLM beta by GLMsingle toolbox, it return beta values of all trials, then put it as fmri_img to fit by searchlight analysis. img_mask is brainmask, process_mask is a reward-related mask refered from neurosynth. the main code is as below:

n_jobs = 2
cv = KFold(n_splits=4)
#cv = LeaveOneGroupOut()

searchlight2 = nilearn.decoding.SearchLight(
        mask_img, # this mask is a brainmask (91*109*91)
        process_mask_img=process_mask_img,  this mask is download from Neurosynth(reward map) and resampled into (91*109*91)
        radius=4,
        n_jobs = n_jobs,
        verbose=1,
        cv=cv,
)
searchlight2.fit(fmri_img, labels)

probably worth checking if GLMsingle gives you some mask of where it computed a GLM so you can check if all the voxels actually have some betas

don’t remember how GLMsingle works, so you may have to look into their doc

Yes, exactly. I checked the glm beta map found some voxels have nan value and I try to use nilearn.image.clean_img to set nan into zeros. I also found in your source script “nifti_spheres_masker.py” give same way to do that: it mentioned contains nan, it will has a warning"the imgs you have fed into fit_transform() contains NaN values which will be converted to zeroes."So even I have converted nan to zeros, the error is still there.

pretty sure that if all the voxel in that sphere contain zeros then you will get the error

I think you need to find from GLMsingle a mask that tells you in which voxels the GLM was estimated