AttributeError: 'numpy.ndarray' object has no attribute 'func'

Hello,
I am working on a subject on my local pc
I did preprocessing through fmriprep on docker.
I used the

when I wanted to run
import nibabel as nib
from nibabel.testing import data_path
import numpy as np
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’]

Load the functional datasets

a = nib.load(’/home/roya/outputneww2/sub-1001/ses-01/func/sub-1001_ses-01_task-rest_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz’)
data = a.get_fdata()
print(‘First subject resting-state nifti image (4D) is located at: %s’ %
data.func[0])

To retrieve the atlas and the data;

I faced this error;


AttributeError Traceback (most recent call last)
/tmp/ipykernel_4701/2610845449.py in
11 data = a.get_fdata()
12 print(‘First subject resting-state nifti image (4D) is located at: %s’ %
—> 13 data.func[0])
14 # print(‘First functional nifti image (4D) is at: %s’ %
15 # data.func[0]) # 4D data

AttributeError: ‘numpy.ndarray’ object has no attribute ‘func’

actually I’ve have already used this codes to xtract timeseries from ROIs using fmriprep data;

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwi75fzH-_H5AhWmMVkFHf2GCyAQFnoECAkQAQ&url=https%3A%2F%2Fnideconv.readthedocs.io%2Fen%2Flatest%2F_downloads%2F2ca39f450881072366a34e648b33a849%2Fextract_timeseries_fmriprep.py&usg=AOvVaw0ufc80XcATGm4GVN4HUX9e

but my next goal is extracting the connectivity R values between the cortical regions.
(for that I’m using

)

Any suggestion would be appreciate.
Best, Roqa

Hi,

I think part of your answer may have been left off.

You defined data as data = a.get_fdata(). Therefore, data is a numerical array, since that is the output of get_fdata(). Arrays do not have the property func.

It looks like this line is only supposed to print the location of the file, which you already specified earlier in the line where you define a. Sounds like you should just say

path_to_file = ’/home/roya/outputneww2/sub-1001/ses-01/func/sub-1001_ses-01_task-rest_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz’
a = nib.load(path_to_file)
data = a.get_fdata()
print(‘First subject resting-state nifti image (4D) is located at: %s’ %
path_to_file)

Best,
Steven

Thank you so much Steven,

when I used the cmd you suggested, I faced this error;

File “/tmp/ipykernel_4701/4224532613.py”, line 15
path_to_file = ’/home/roya/outputneww2/sub-1001/ses-01/func/sub-1001_ses-01_task-rest_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz’
^
SyntaxError: invalid character in identifier

I am appreciative of your time and help
Best

You might want to retype the ' surrounding the path. Quotes can act weird if copied and pasted.

Hi, there some issues with this, and I suggest that you familiarize yourself with some concepts before trying to do your analysis. An fmri analysis is a difficult way for one to become familiar with coding. I would also open a new issue since the following are not tied to your original question.

You are not supposed to use all confounds to denoise your signals, only a subset (depending on your needs). Nilearn has an API for loading fmriprep confounds that you may find useful. nilearn.interfaces.fmriprep.load_confounds - Nilearn ← shows you how to do it, and also has papers describing considerations for choosing the right confounds.

This error is because Pandas assumes spreadsheets are comma-delimited, whereas the confounds are tab-delimited (hence all of those “\t”). You can simply add a delimiter='\t' argument to your pd.read_csv command.

Best,
Steven

sure, thank you so much for the links and information.
Best
Roqa