Permalink
Browse files

Merge pull request #341 from satra/fix/spmmodel

Fix/spmmodel
  • Loading branch information...
2 parents 2416b65 + 394ecfb commit 1764f0f7d8a54245cc7bced1e2156b30a74a4ad1 @chrisfilo chrisfilo committed Mar 23, 2012
View
@@ -1,3 +1,8 @@
+Since 0.5.2
+===========
+
+* FIX: SPM model generation when output units is in scans
+
Release 0.5.2 (Mar 14, 2012)
============================
@@ -271,6 +271,9 @@ def _generate_standard_design(self, infolist,
each run
"""
sessinfo = []
+ output_units = 'secs'
+ if 'output_units' in self.inputs.traits():
+ output_units = self.inputs.output_units
for i, info in enumerate(infolist):
sessinfo.insert(i, dict(cond=[]))
if isdefined(self.inputs.high_pass_filter_cutoff):
@@ -281,11 +284,11 @@ def _generate_standard_design(self, infolist,
sessinfo[i]['cond'][cid]['name'] = info.conditions[cid]
sessinfo[i]['cond'][cid]['onset'] = scale_timings(info.onsets[cid],
self.inputs.input_units,
- 'secs',
+ output_units,
self.inputs.time_repetition)
sessinfo[i]['cond'][cid]['duration'] = scale_timings(info.durations[cid],
self.inputs.input_units,
- 'secs',
+ output_units,
self.inputs.time_repetition)
if hasattr(info, 'amplitudes') and info.amplitudes:
sessinfo[i]['cond'][cid]['amplitudes'] = info.amplitudes[cid]
@@ -1,5 +1,6 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
+from copy import deepcopy
import os
from shutil import rmtree
from tempfile import mkdtemp
@@ -44,27 +45,35 @@ def test_modelgen_spm_concat():
tempdir = mkdtemp()
filename1 = os.path.join(tempdir, 'test1.nii')
filename2 = os.path.join(tempdir, 'test2.nii')
- Nifti1Image(np.random.rand(10, 10, 10, 50), np.eye(4)).to_filename(filename1)
- Nifti1Image(np.random.rand(10, 10, 10, 50), np.eye(4)).to_filename(filename2)
+ Nifti1Image(np.random.rand(10, 10, 10, 30), np.eye(4)).to_filename(filename1)
+ Nifti1Image(np.random.rand(10, 10, 10, 30), np.eye(4)).to_filename(filename2)
s = SpecifySPMModel()
s.inputs.input_units = 'secs'
- s.inputs.output_units = 'scans'
s.inputs.concatenate_runs = True
- setattr(s.inputs, 'output_units', 'scans')
- yield assert_equal, s.inputs.output_units, 'scans'
+ setattr(s.inputs, 'output_units', 'secs')
+ yield assert_equal, s.inputs.output_units, 'secs'
s.inputs.functional_runs = [filename1, filename2]
s.inputs.time_repetition = 6
s.inputs.high_pass_filter_cutoff = 128.
- info = [Bunch(conditions=['cond1'], onsets=[[2, 50, 100, 180]], durations=[[1]], amplitudes=None,
- pmod=None, regressors=None, regressor_names=None, tmod=None),
- Bunch(conditions=['cond1'], onsets=[[30, 40, 100, 150]], durations=[[1]], amplitudes=None,
- pmod=None, regressors=None, regressor_names=None, tmod=None)]
- s.inputs.subject_info = info
+ info = [Bunch(conditions=['cond1'], onsets=[[2, 50, 100, 170]], durations=[[1]]),
+ Bunch(conditions=['cond1'], onsets=[[30, 40, 100, 150]], durations=[[1]])]
+ s.inputs.subject_info = deepcopy(info)
res = s.run()
yield assert_equal, len(res.outputs.session_info), 1
yield assert_equal, len(res.outputs.session_info[0]['regress']), 1
+ yield assert_equal, np.sum(res.outputs.session_info[0]['regress'][0]['val']), 30
yield assert_equal, len(res.outputs.session_info[0]['cond']), 1
- yield assert_almost_equal, np.array(res.outputs.session_info[0]['cond'][0]['onset']), np.array([2.0, 50.0, 100.0, 180.0, 330.0, 340.0, 400.0, 450.0])
+ yield assert_almost_equal, np.array(res.outputs.session_info[0]['cond'][0]['onset']), np.array([2.0, 50.0, 100.0, 170.0, 210.0, 220.0, 280.0, 330.0])
+ setattr(s.inputs, 'output_units', 'scans')
+ yield assert_equal, s.inputs.output_units, 'scans'
+ s.inputs.subject_info = deepcopy(info)
+ res = s.run()
+ yield assert_almost_equal, np.array(res.outputs.session_info[0]['cond'][0]['onset']), np.array([2.0, 50.0, 100.0, 170.0, 210.0, 220.0, 280.0, 330.0])/6
+ s.inputs.concatenate_runs = False
+ s.inputs.subject_info = deepcopy(info)
+ s.inputs.output_units = 'secs'
+ res = s.run()
+ yield assert_almost_equal, np.array(res.outputs.session_info[0]['cond'][0]['onset']), np.array([2.0, 50.0, 100.0, 170.0])
rmtree(tempdir)
@@ -504,7 +504,7 @@ def create_tbss_non_FA(name='tbss_non_FA'):
inputnode.distance_map
Outputs::
-
+
outputnode.projected_nonFA_file
"""
@@ -42,7 +42,7 @@
'FSL',
'FS',
'Info',
- 'SPM',
+ '^SPM',
'Tester',
'Spec$',
'Numpy'

0 comments on commit 1764f0f

Please sign in to comment.