Nipype ArtifactDetection question

I’m playing around with nipype’s ArtifactDetection function to create a censor file to use in my GLM, however, I’m confused by what needs to be in the “realignment_parameters” field. My command is:

import nipype.algorithms.rapidart as ra

ad = ra.ArtifactDetect()
ad.inputs.realigned_files = data_dir + '/sub-000*run-01_space-MNI152NLin2009cAsym_desc-smoothAROMAnonaggr_bold.nii.gz'
ad.inputs.mask_type = 'file'
ad.inputs.realignment_parameters = data_dir + '/sub-000*run-01_desc-confounds_regressors.tsv'
ad.inputs.mask_file = data_dir + '/brain_mask.nii.gz'
ad.inputs.parameter_source = 'AFNI'
ad.inputs.norm_threshold = 1
ad.inputs.use_differences = [True, False]
ad.inputs.zintensity_threshold = 3
ad.run() 

Which leads the the following error message:

  File "ArtifactDetect.py", line 20, in <module>
    ad.run() 
  File "/N/u/dlevitas/Carbonate/.local/lib/python2.7/site-packages/nipype-1.1.2-py2.7.egg/nipype/interfaces/base/core.py", line 521, in run
    runtime = self._run_interface(runtime)
  File "/N/u/dlevitas/Carbonate/.local/lib/python2.7/site-packages/nipype-1.1.2-py2.7.egg/nipype/algorithms/rapidart.py", line 624, in _run_interface
    imgf, motparamlist[i], i, cwd=os.getcwd())
  File "/N/u/dlevitas/Carbonate/.local/lib/python2.7/site-packages/nipype-1.1.2-py2.7.egg/nipype/algorithms/rapidart.py", line 486, in _detect_outliers_core
    mc_in = np.loadtxt(motionfile)
  File "/gpfs/hps/soft/rhel7/python/2.7.13a/lib/python2.7/site-packages/numpy-1.13.0.dev0+9c3d247-py2.7-linux-x86_64.egg/numpy/lib/npyio.py", line 1024, in loadtxt
    items = [conv(val) for (conv, val) in zip(converters, vals)]
  File "/gpfs/hps/soft/rhel7/python/2.7.13a/lib/python2.7/site-packages/numpy-1.13.0.dev0+9c3d247-py2.7-linux-x86_64.egg/numpy/lib/npyio.py", line 725, in floatconv
    return float(x)
ValueError: could not convert string to float: csf

So I realize that I can’t input each run’s confounds_regressors.tsv file, but I can’t quite tell from the documentation what I should be using instead.

Thank for you the help.

Nevermind, I was able to fix it by grabbing the motion parameter columns from the confounds_regressors.tsv file

Which specific parameters did you use?
Can you share the specific method you used?

Thanks

Hi @orduek, are you asking which parameters from the confounds_regressors.tsv file I used for ArtifactDetection? If so, I was just using the motion parameters, and my code was this:

import glob
import argparse
import pandas as pd
import nipype.algorithms.rapidart as ra

data_dir = 'bids_root_dir/derivatives/fmriprep/sub-000/func'

motion_parameters = pd.read_csv(data_dir + '/sub-000_task-std_run-01_desc-confounds_regressors.tsv', delimiter='\t').loc[:,['trans_x','trans_y','trans_z','rot_x','rot_y','rot_z']]
motion_parameters.to_csv(data_dir + '/sub-000_task-std_run-01_desc-confounds_regressors_MoPar.csv', sep='\t', index=False, header=False)

ad = ra.ArtifactDetect()
ad.inputs.realigned_files = data_dir + '/sub-000_task-std_run-01_space-MNI152NLin2009cAsym_desc-smoothAROMAnonaggr_bold.nii.gz'
ad.inputs.mask_type = 'spm_global'
ad.inputs.realignment_parameters = data_dir + '/sub-000_task-std_run-01_desc-confounds_regressors_MoPar.csv'
ad.inputs.parameter_source = 'FSL'
ad.inputs.norm_threshold = 1
ad.inputs.use_differences = [True, False]
ad.inputs.zintensity_threshold = 3
ad.run()

My motivation for trying this out was because I was trying to create a censor file that I could pass into the -censor option of AFNI’s 3dDeconvolve command, after running fmriprep. I’ve recently switched over to FSL though, so I don’t really use AFNI much, and consequently haven’t been using nipype’s ArtifactDetection at the moment.

2 Likes

Thanks so much for sharing this solution! Saved me a lot of time! :slight_smile: