Extracting nuisance regressed timeseries via nilearn

I’m switching my analysis pipeline to nilearn and have a few basic questions regarding signal extraction. Using my fMRIPrep output, I’m trying to extract the nuisance regressed signal from a HarvardOxford atlas ROI mask that I’ve generated, with selected fMRIprep confounds. My code is:

vols_remove = 10 # number of volumes to remove at beginning of each func BOLD

roi_mask_img = img.load_img(roi_mask_file)
roi_masker = NiftiMasker(mask_img=roi_mask_img, 
                         detrend=False,
                         standardize="zscore",
                         smoothing_fwhm=6,
                         standardize_confounds=True,
                         mask_strategy="background",
                         dtype = "float32",
                         verbose=1)

func_file = "sub-1_task-lost_run-1_space-MNI152NLin6Asym_res-2_desc-preproc_bold.nii.gz"
func_img = img.load_img(func_file)
func_img = func_img.slicer[:,:,:,vols_remove:]

extracted_confounds = pd.read_csv(extracted_confounds_file) # selected confounds from sub-1_task-lost_run-1_desc-confounds_timeseries.tsv
extracted_confounds = extracted_confounds.iloc[vols_remove:,:]

nuisance_regressed_roi_timeseries = roi_masker.fit_transform(func_img, confounds=extracted_confounds.values)
nuisance_regressed_roi_timeseries = np.mean(nuisance_regressed_roi_timeseries, axis=1)

From this I have two questions:

1). The func_img has not been spatially smoothed; does the NiftiMasker’s smoothing_fwhm parameter perform the spatial smoothing on the functional data, or do I still need to perform that step on the functional data myself?

2). I’ve included the cosine_XX DCT-basis regressors in my selected confounds. Is it therefore appropriate to set NiftiMasker’s detrend=False, since that functionality will be included in the .fit_transform step?

Thanks for the assistance.

Hi,
Regarding 1: Yes, the NiftiMasker will smooth the data, do you should not do it addiitonally.
Regarding 2: Yes, there is no point in duplicating detrending between the confounds basis and the masker object.

Note that we have recently added functionalities for high-level integration of fmriprep confounds estimates into Nilearn.

Best,

Bertrand

Thanks @bthirion. I’ll take a look at the new nilearn functionalities as well.