NiPype: Error inputting to SpecifySPMModel

Dear All,

I have a preprocessing worklfow that appears to run without any problems. I then connect this to the 1st level workflow:

metaflow.connect([(preproc, l1analysis, [('realign.realignment_parameters',
                                      'modelspec.realignment_parameters'),
                                     ('smooth.smoothed_files',
                                      'modelspec.functional_runs'),
                                     ('art.outlier_files',
                                      'modelspec.outlier_files'),

The inputs are then connected to this:

metaflow.connect([(infosource, selectfiles, [('subject_id', 'subject_id'), ('session_id', 'session_id')]),
              (selectfiles, preproc, [('func', 'reset_origin_func.niftis')]),
              (selectfiles, preproc, [('struc', 'reset_origin_struc.niftis')]),
              (infosource, getsubjectinfo, [('subject_id', 'subject_id')]),
              (getsubjectinfo, l1analysis, [('subject_info', 'modelspec.subject_info')]),
              (infosource, l1analysis, [('contrasts', 'conestimate.contrasts')]),

It seems that it is at the connection between getsubejctinfo and l1analysis the pipeline stumbles: I receive an error message:

"TypeError: can't multiply sequence by non-int of type 'float'
Interface SpecifySPMModel failed to run."

The firstlevel node that it fails on is:

modelspec = Node(SpecifySPMModel(concatenate_runs=False,
                             input_units='secs', output_units='secs',
                             time_repetition=TR,
                             high_pass_filter_cutoff=128),
             name="modelspec")

I wondered if this may be related to me inputting the task details incorrectly - this is the getsubjectinfo function that connects to the modelspec node:

def get_subject_info(subject_id):
    from nipype.interfaces.base import Bunch
    condition_names = ['rest', 'control', 'stress']

    onsets_run1 = [[0, 220.5], [10.5, 231], [98.7, 319.2]]
    onsets_run3 = [[0], [10.5], [98.7]]
    onset_list = [(onsets_run1), (onsets_run1), (onsets_run3)]

    durations_run1 = [[10.5],[88.2],[98.7]]
    durations_run3 = [[10.5],[88.2],[342.3]]
    durations_list = [(durations_run1), (durations_run1), (durations_run3)]

    subjectinfo = []
    for r in range(1):
        subjectinfo.insert(r,
                       Bunch(conditions=condition_names,
                             onsets=[onset_list[r]],
                             durations=[durations_list[r]],
                             amplitudes=None,
                             tmod=None,
                             pmod=None,
                             regressor_names=None,
                             regressors=None))
return subjectinfo

getsubjectinfo = Node(Function(input_names=['subject_id'], output_names=['subject_info'],
                           function=get_subject_info),
                  name='getsubjectinfo')]

From the error message I wondered whether some timings were being inputted as a string but this doesn’t seem to be the case.

Any help most appreciated!

Many Thanks

Rob

Hi @rob, did a crashfile get produced? If so, that may be a better way to debug the problem

Thanks mgxd - the crash file is below, I wasn’t really able to decipher it though

I wondered if this line pointed to the problem:

timelist = [np.max([0., _scalefactor * t]) for t in timelist]

Suggesting there is a problem with my list of timings but I can’t tell what this problem may be

  File: crash-20170317-204114-k1201869-modelspec.a0-f6aac261-95f3-43dd-aa91-a8cfaf994a71.pklz
    Node: metaflow.l1analysis.modelspec.a0
    Working directory: /home/k1201869/restingstate2017/workingdir_prepro/metaflow/l1analysis/_session_id_run1_subject_id_subject001/modelspec

Node inputs:

concatenate_runs = False
event_files = <undefined>
functional_runs = ['/home/k1201869/restingstate2017/workingdir_prepro/metaflow/preproc/_session_id_run1_subject_id_subject001/smooth/swrrun1_reset.nii']
high_pass_filter_cutoff = 128.0
ignore_exception = False
input_units = secs
outlier_files = ['/home/k1201869/restingstate2017/workingdir_prepro/metaflow/preproc/_session_id_run1_subject_id_subject001/art/art.rrun1_reset_outliers.txt']
output_units = secs
realignment_parameters = ['/home/k1201869/restingstate2017/workingdir_prepro/metaflow/preproc/_session_id_run1_subject_id_subject001/realign/rp_run1_reset.txt']
subject_info = [Bunch(amplitudes=None, conditions=['rest', 'control', 'stress'], durations=[[[10.5], [88.2], [98.7]]], onsets=[[[0, 220.5], [10.5, 231], [98.7, 319.2]]], pmod=None, regressor_names=None, regressors=None, tmod=None), 
Bunch(amplitudes=None, conditions=['rest', 'control', 'stress'], durations=[[[10.5], [88.2], [98.7]]], onsets=[[[0, 220.5], [10.5, 231], [98.7, 319.2]]], pmod=None, regressor_names=None, regressors=None, tmod=None), 
Bunch(amplitudes=None, conditions=['rest', 'control', 'stress'], durations=[[[10.5], [88.2], [342.3]]], onsets=[[[0], [10.5], [98.7]]], pmod=None, regressor_names=None, regressors=None, tmod=None)]
time_repetition = 2.1


Traceback: 
Traceback (most recent call last):
  File "/home/k1201869/restingstate2017/workingdir_prepro/metaflow/batch/pyscript_20170317_204013_metaflow.l1analysis_modelspec.a0.py", line 32, in <module>
result = info['node'].run(updatehash=info['updatehash'])
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 394, in run
self._run_interface()
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 504, in _run_interface
self._result = self._run_command(execute)
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 630, in _run_command
result = self._interface.run()
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1043, in run
runtime = self._run_wrapper(runtime)
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1000, in _run_wrapper
runtime = self._run_interface(runtime)
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/algorithms/modelgen.py", line 408, in _run_interface
self._generate_design()
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/algorithms/modelgen.py", line 522, in _generate_design
super(SpecifySPMModel, self)._generate_design(infolist=infolist)
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/algorithms/modelgen.py", line 402, in _generate_design
outliers=outliers)
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/algorithms/modelgen.py", line 309, in _generate_standard_design
self.inputs.time_repetition)
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/algorithms/modelgen.py", line 147, in scale_timings
timelist = [np.max([0., _scalefactor * t]) for t in timelist]
TypeError: can't multiply sequence by non-int of type 'float'
Interface SpecifySPMModel failed to run.

The problem could be due to the number of lists you have in your subject_info.

  • onsets=[[[0, 220.5], [10.5, 231], [98.7, 319.2]]]

should probably be

  • onsets=[[0, 220.5], [10.5, 231], [98.7, 319.2]]

durations should also be structured like this. There a nice example in the docs found here

Thanks again - the pipeline runs all the way through now. My one final problem is that it generates contrasts separately for each individual run. I don not want to concatenate the runs, but I would like all runs to be modelled at once so I just have one set of contrasts per subject (i.e. as one would normally do in SPM).

I think the issue is again in the get_subject_info function:

# Contrasts
cont01 = ['stress>control', 'T', condition_names, [0, -1, 1]]
cont02 = ['control>stress', 'T', condition_names, [0, 1, -1]]
contrast_list = [cont01, cont02]

# Task onsets and durations
def get_subject_info(subject_id):
    from nipype.interfaces.base import Bunch
    condition_names = ['rest', 'control', 'stress']
    onset_run1_rest = [0, 220.5]
    onset_run1_control = [10.5, 231]
    onset_run1_stress = [98.7, 319.2]
    onset_run3_rest = [0]
    onset_run3_control = [10.5]
    onset_run3_stress = [98.7]

    onsets_run3 = [[0], [10.5], [98.7]]
    onset_list = [(onset_run1_rest), (onset_run1_control), (onset_run1_stress),
                  (onset_run1_rest), (onset_run1_control), (onset_run1_stress),
                  (onset_run3_rest), (onset_run3_control), (onset_run3_stress)]

    durations_run1 = [[10.5],[88.2],[98.7]]
    durations_run3 = [[10.5],[88.2],[342.3]]
    durations_list = [(durations_run1), (durations_run1), (durations_run3)]

    subjectinfo = []
    for r in range(1):
        onsets = [onset_list[r*2],onset_list[r*2+1], onset_list[r*2+2]]
        subjectinfo.insert(r,
                           Bunch(conditions=condition_names,
                                 onsets=onsets,
                                 durations=durations_list[r],
                                 amplitudes=None,
                                 tmod=None,
                                 pmod=None,
                                 regressor_names=None,
                                 regressors=None))
    return subjectinfo

getsubjectinfo = Node(Function(input_names=['subject_id'], output_names=['subject_info'],
                               function=get_subject_info),
                      name='getsubjectinfo')

There are 3 runs but if I put anything other than ‘1’ in:

for r in range(1):

the pipeline crashes.

Again any help most gratefully received and please ask me to clarify if anything is unclear.

Many thanks,

Rob

Hi, could you post the crashfile again? Also cc-ing @satra for another pair of eyes

Here is the crash file if I put:

for r in range(3):

rather than

for r in range(1):

Thanks again!

File: crash-20170321-095309-k1201869-normalize.a0-69e953ce-e7f0-433e-b813-b5a9635e6871.pklz
Node: metaflow.preproc.normalize.a0
Working directory: /home/k1201869/restingstate2017/workingdir_prepro/metaflow/preproc/_session_id_run1_subject_id_subject001/normalize


Node inputs:

affine_regularization_type = <undefined>
apply_to_files = ['/home/k1201869/restingstate2017/workingdir_prepro/metaflow/preproc/_session_id_run1_subject_id_subject001/coregister/rrun1_reset.nii']
bias_fwhm = <undefined>
bias_regularization = <undefined>
deformation_file = <undefined>
ignore_exception = False
image_to_align = /home/k1201869/restingstate2017/data/subject001/struc/struc_reset.nii
jobtype = estwrite
matlab_cmd = <undefined>
mfile = True
paths = ['/cns_zfs/system/system_ce51_64/spm/spm-12-20141016/']
sampling_distance = <undefined>
smoothness = <undefined>
tpm = <undefined>
use_mcr = <undefined>
use_v8struct = True
warping_regularization = <undefined>
write_bounding_box = <undefined>
write_interp = <undefined>
write_voxel_sizes = [2.0, 2.0, 2.0]



Traceback: 
Traceback (most recent call last):
  File "/home/k1201869/anaconda2/lib/python2.7/site-packages/nipype/pipeline/plugins/base.py", line 543, in _get_result
    raise IOError(error_message)
IOError: Job id (3479096) finished or terminated, but results file does not exist after (5.0) seconds. Batch dir contains crashdump file if node raised an exception.
Node working directory: (/home/k1201869/restingstate2017/workingdir_prepro/metaflow/preproc/_session_id_run1_subject_id_subject001/normalize)

@rob this error looks like a problem with the Normalize node. Could you try clearing your working directory and rerunning the script with for r in range(3)?

Hi,

Apologies - the crash file I posted was incorrect. The right one is below. The issue seems to be that timings for all 3 runs are being inputted to each run, rather than timings for run1 to run1, timings for run2 to run2 etc.

I imagine the fix may be fairly straightforward but any advice most appreciated

File: crash-20170322-195550-k1201869-modelspec.a0-f96f2687-dfc6-4375-af83-7a313c763f83.pklz
Node: metaflow.l1analysis.modelspec.a0
Working directory: /home/k1201869/restingstate2017/workingdir_prepro/metaflow/l1analysis/_session_id_run1_subject_id_subject001/modelspec


Node inputs:

concatenate_runs = False
event_files = <undefined>
functional_runs = ['/home/k1201869/restingstate2017/workingdir_prepro/metaflow/preproc/_session_id_run1_subject_id_subject001/smooth/swrrun1_reset.nii']
high_pass_filter_cutoff = 128.0
ignore_exception = False
input_units = secs
outlier_files = ['/home/k1201869/restingstate2017/workingdir_prepro/metaflow/preproc/_session_id_run1_subject_id_subject001/art/art.rrun1_reset_outliers.txt']
output_units = secs
realignment_parameters = ['/home/k1201869/restingstate2017/workingdir_prepro/metaflow/preproc/_session_id_run1_subject_id_subject001/realign/rp_run1_reset.txt']
subject_info = [Bunch(amplitudes=None, conditions=['rest', 'control', 'stress'], durations=[[10.5], [88.2], [98.7]], onsets=[[0, 220.5], [10.5, 231], [98.7, 319.2]], pmod=None, regressor_names=None, regressors=None, tmod=None), Bunch(amplitudes=None, conditions=['rest', 'control', 'stress'], durations=[[10.5], [88.2], [98.7]], onsets=[[0, 220.5], [10.5, 231], [98.7, 319.2]], pmod=None, regressor_names=None, regressors=None, tmod=None), Bunch(amplitudes=None, conditions=['rest', 'control', 'stress'], durations=[[10.5], [88.2], [342.3]], onsets=[[0], [10.5], [98.7]], pmod=None, regressor_names=None, regressors=None, tmod=None)]
time_repetition = 2.1



Traceback: 
Traceback (most recent call last):
  File "/home/k1201869/restingstate2017/workingdir_prepro/metaflow/batch/pyscript_20170322_195450_metaflow.l1analysis_modelspec.a0.py", line 32, in <module>
    result = info['node'].run(updatehash=info['updatehash'])
  File "/home/k1201869/anaconda2/envs/MRS_conda/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 394, in run
    self._run_interface()
  File "/home/k1201869/anaconda2/envs/MRS_conda/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 504, in _run_interface
    self._result = self._run_command(execute)
  File "/home/k1201869/anaconda2/envs/MRS_conda/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 630, in _run_command
    result = self._interface.run()
  File "/home/k1201869/anaconda2/envs/MRS_conda/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1043, in run
    runtime = self._run_wrapper(runtime)
  File "/home/k1201869/anaconda2/envs/MRS_conda/lib/python2.7/site-packages/nipype/interfaces/base.py", line 1000, in _run_wrapper
    runtime = self._run_interface(runtime)
  File "/home/k1201869/anaconda2/envs/MRS_conda/lib/python2.7/site-packages/nipype/algorithms/modelgen.py", line 408, in _run_interface
    self._generate_design()
  File "/home/k1201869/anaconda2/envs/MRS_conda/lib/python2.7/site-packages/nipype/algorithms/modelgen.py", line 522, in _generate_design
    super(SpecifySPMModel, self)._generate_design(infolist=infolist)
  File "/home/k1201869/anaconda2/envs/MRS_conda/lib/python2.7/site-packages/nipype/algorithms/modelgen.py", line 402, in _generate_design
    outliers=outliers)
  File "/home/k1201869/anaconda2/envs/MRS_conda/lib/python2.7/site-packages/nipype/algorithms/modelgen.py", line 345, in _generate_standard_design
    sessinfo[i]['scans'] = functional_runs[i]
IndexError: list index out of range
Interface SpecifySPMModel failed to run.

Hi,

Was this ever resolved? I am getting this exact same error (‘IndexError: list index out of range’ for sessinfo[i][‘scans’] = functional_runs[i]). I think it has something to do with the fact that only one functional run is listed as an input to the node, but subject info has multiple bunches. Although I could be way off. I’m quite stuck and would appreciate any help!