Hello NeuroStars community,
I’ve come across an off-by-one error while utilizing the Glasser360 atlas in tandem with the NiftiLabelsMasker from nilearn. What’s particularly puzzling is that I’ve run similar code with multiple atlases in the past without any hiccups, making the current issue with the Glasser360 atlas stand out.
The Core of the Problem:
Upon employing NiftiLabelsMasker.fit_transform
to produce a 2D samples x features array, I’m met with an array with dimensions of 210 x 359
. The number of samples is correct, but the number of features is off by 1 - I would expect this length to match my feature list’s length of 360.
Snippet of the Troublesome Code:
masker = input_data.NiftiLabelsMasker(atlasI, labels=labelL, standardize=False, memory=f"{workD}nilearn_cache", verbose=0, detrend=False)
... # [Code for reports generation omitted for clarity]
masker.fit(cleanI)
maskedDat = masker.fit_transform(cleanI)
if AtlasDictCount == 0:
atlasesDF = pd.DataFrame(maskedDat, columns=labelL[1:])
This results in an error when attempting to create atlasesDF
:
ValueError Traceback (most recent call last)
/home/scratch/ipykernel_29273/2381995345.py in <module>
460 # atlas data (maskedDat) into atlasesDF
461 if AtlasDictCount == 0:
--> 462 atlasesDF = pd.DataFrame(
463 maskedDat,columns=labelL[1:]
464 )
ValueError: Shape of passed values is (210, 359), indices imply (210, 360)
(Note: Full stack trace excluded for conciseness.)
My first inclination was that this had something to do with the ‘background’ element in my features list, but I do not believe this is the case. The length of my features list, len(labelL)
is 361 - background + 360 ROIs
. I use labelL[1:]
to omit the background when creating atlasesDF
, where the error occurs.
Additional Information:
- I sourced the Glasser atlas from the
brainspaces/glasser360
repository. cleanI
in my script pertains to the subject’s regressed NIfTI, andatlasI
relates to the atlas NIfTI.- I am using version 0.8.1 of nilearn.
- Notably, I encountered a similar issue with the Glasser180 atlas:
ValueError: Shape of passed values is (210, 179), indices imply (210, 180)
My Inquiry:
Has anyone come across this kind of dimension discrepancy while using NiftiLabelsMasker with the Glasser atlas? I’m trying to discern if this is a quirk of the nilearn function or a fundamental flaw in my methodology. Your insights or potential solutions would be immensely appreciated.
Thank you in advance! Please let me know if anything else is required for clarification - I’m a bit new to using nilearn.