Extract time series to get connectome with Neurovault

I’d like to apply this example: Nilearn: Statistical Analysis for NeuroImaging in Python — Machine learning for NeuroImaging

to a Neurovault image. I get this error when I try to apply GraphicalLassoCV.

data = datasets.fetch_neurovault_ids(image_ids=[34])
img = data.images

from nilearn import datasets
atlas = datasets.fetch_atlas_msdl()
# Loading atlas image stored in 'maps'
atlas_filename = atlas['maps']
# Loading atlas data stored in 'labels'
labels = atlas['labels']

from nilearn.input_data import NiftiMapsMasker
masker = NiftiMapsMasker(maps_img=atlas_filename, standardize=True,
                         memory='nilearn_cache', verbose=5)

time_series = masker.fit_transform(img)

try:
    from sklearn.covariance import GraphicalLassoCV
except ImportError:
    # for Scitkit-Learn < v0.20.0
    from sklearn.covariance import GraphLassoCV as GraphicalLassoCV

estimator = GraphicalLassoCV()
estimator.fit(time_series)

In case the issue was with the Neurovault file, I tried using spm_auditory by making these changed:

data = datasets.fetch_spm_auditory(subject_id='sub003')
img = data.func1[0]

but got the same error.

Hi @scrambledegg

In the example you linked, the data fetcher downloads fMRI data for one subject. You get a 4D image of shape (50, 59, 50, 168), meaning that you have 168 time steps in the time series that you extract afterwards.
In your example code, you get 3D statistical maps (through fetch_neurovault_ids and fetch_spm_auditory). Your code results in time series with only one time step (you can check that time_series.shape is (1, 39) where 39 is the number of spatial maps and 1 is the number of time points), which is causing the error with the GraphicalLassoCV down the road.

HTH
Nicolas

Thanks for explaining. I removed the [0] and just wrote img = data.func and it works now