nipype icon indicating copy to clipboard operation
nipype copied to clipboard

ENH: Enable orthogonalization in SPM models via SpecifyModel

Open hstojic opened this issue 6 years ago • 13 comments
trafficstars

Summary

SPM 12 has an option to switch off the default orthogonolisation of parametric regressors, but it seems that option cannot be set from Nipype - I implemented it here with simple few lines, supplying orth argument as an additional input in the sessioninfo object. Updated the example and function description.

See discussion in issue #2811

Acknowledgment

  • [x] I acknowledge that this contribution will be available under the Apache 2 license.

hstojic avatar Jan 31 '19 20:01 hstojic

Codecov Report

Merging #2870 into master will decrease coverage by 0.69%. The diff coverage is 20%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #2870     +/-   ##
=========================================
- Coverage   67.49%   66.79%   -0.7%     
=========================================
  Files         342      342             
  Lines       43562    43567      +5     
  Branches     5422     5425      +3     
=========================================
- Hits        29402    29101    -301     
- Misses      13458    13723    +265     
- Partials      702      743     +41
Flag Coverage Δ
#smoketests 48.64% <20%> (-1.85%) :arrow_down:
#unittests 64.88% <0%> (-0.04%) :arrow_down:
Impacted Files Coverage Δ
nipype/algorithms/modelgen.py 59.27% <20%> (-4.09%) :arrow_down:
nipype/algorithms/rapidart.py 35% <0%> (-29.42%) :arrow_down:
nipype/interfaces/spm/base.py 68.64% <0%> (-18.49%) :arrow_down:
nipype/interfaces/fsl/model.py 75.3% <0%> (-5.32%) :arrow_down:
nipype/interfaces/spm/preprocess.py 52.88% <0%> (-4.15%) :arrow_down:
nipype/pipeline/plugins/legacymultiproc.py 61.5% <0%> (-3.5%) :arrow_down:
nipype/utils/misc.py 65.43% <0%> (-1.24%) :arrow_down:
nipype/pipeline/engine/workflows.py 77.77% <0%> (-1.18%) :arrow_down:
nipype/interfaces/io.py 54.36% <0%> (-0.71%) :arrow_down:
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 98beb0a...507aafc. Read the comment docs.

codecov-io avatar Feb 04 '19 13:02 codecov-io

Codecov Report

Merging #2870 into master will decrease coverage by 1.73%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2870      +/-   ##
==========================================
- Coverage   67.49%   65.76%   -1.74%     
==========================================
  Files         342      343       +1     
  Lines       43562    44117     +555     
  Branches     5422     5607     +185     
==========================================
- Hits        29402    29013     -389     
- Misses      13458    14208     +750     
- Partials      702      896     +194
Flag Coverage Δ
#smoketests 42.53% <0%> (-7.97%) :arrow_down:
#unittests 65.2% <0%> (+0.28%) :arrow_up:
Impacted Files Coverage Δ
nipype/algorithms/modelgen.py 54.56% <0%> (-8.8%) :arrow_down:
nipype/algorithms/rapidart.py 35% <0%> (-29.42%) :arrow_down:
nipype/interfaces/fsl/model.py 55.26% <0%> (-25.35%) :arrow_down:
nipype/interfaces/spm/base.py 68.64% <0%> (-18.49%) :arrow_down:
nipype/workflows/fmri/fsl/preprocess.py 72.67% <0%> (-13.39%) :arrow_down:
nipype/interfaces/fsl/preprocess.py 72.7% <0%> (-9.91%) :arrow_down:
nipype/pipeline/plugins/linear.py 79.06% <0%> (-6.98%) :arrow_down:
nipype/utils/subprocess.py 87.31% <0%> (-6.72%) :arrow_down:
nipype/interfaces/fsl/utils.py 63.8% <0%> (-6.53%) :arrow_down:
... and 25 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 98beb0a...d3ec0aa. Read the comment docs.

codecov-io avatar Feb 04 '19 13:02 codecov-io

just a note that we may have to do something different between SPM12 and prior versions.

in pre SPM12, orth was sequential and order mattered (and interpretation mattered). this was changed in SPM12, where you can orthgonalize things independently to the same variable, but i have not had a chance to play with this. perhaps @gllmflndn can also help us out :)

@hstojic - if you know how this is done, we should incorporate a version specific option.

satra avatar Feb 14 '19 16:02 satra

@hstojic Just a heads up that we're going to try to release on Monday, so it'd be good to have any PRs ready by Friday if possible. (No big deal if we have to push off another month.)

I'll let this note stand in for #2857 and #2861 as well.

effigies avatar Feb 20 '19 14:02 effigies

just a note that we may have to do something different between SPM12 and prior versions.

in pre SPM12, orth was sequential and order mattered (and interpretation mattered). this was changed in SPM12, where you can orthgonalize things independently to the same variable, but i have not had a chance to play with this. perhaps @gllmflndn can also help us out :)

@hstojic - if you know how this is done, we should incorporate a version specific option.

Good catch. I don't know the SPM code well enough to try to create equivalent version for SPM8. For now i would simply condition this on SPM12, sounds good?

hstojic avatar Feb 21 '19 08:02 hstojic

I tried it out with SPM8, it fails in the estimation step but for some other reason related to the output (below). Design step goes fine, SPM8 simply ignores orth option in fmri_spec, so no need for any special treatment.

I updated the code with @effigies suggestions, pushing it shortly.

[Node] Error on "repsup_susan6_ydiff_test_l1_l1pipeline.analysis.estimate" (/media/hstojic/dataneuro/fnclearning_fmri/dProcessed/nipype_work/repsup_susan6_ydiff_test_l1_l1pipeline/analysis/_subject_s010/estimate)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-5-27342c4bf114> in <module>()
     16     l1pipeline.run(
     17         'MultiProc',
---> 18         plugin_args = {'n_procs': pars['resources']['n_cores']}
     19     )
     20     l1pipeline._get_inputs()

/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/pipeline/engine/workflows.pyc in run(self, plugin, plugin_args, updatehash)
    593         if str2bool(self.config['execution']['create_report']):
    594             self._write_report_info(self.base_dir, self.name, execgraph)
--> 595         runner.run(execgraph, updatehash=updatehash, config=self.config)
    596         datestr = datetime.utcnow().strftime('%Y%m%dT%H%M%S')
    597         if str2bool(self.config['execution']['write_provenance']):

/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/pipeline/plugins/base.pyc in run(self, graph, config, updatehash)
    160                         if result['traceback']:
    161                             notrun.append(
--> 162                                 self._clean_queue(jobid, graph, result=result))
    163                         else:
    164                             self._task_finished_cb(jobid)

/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/pipeline/plugins/base.pyc in _clean_queue(self, jobid, graph, result)
    222 
    223         if str2bool(self._config['execution']['stop_on_first_crash']):
--> 224             raise RuntimeError("".join(result['traceback']))
    225         crashfile = self._report_crash(self.procs[jobid], result=result)
    226         if jobid in self.mapnodesubids:

RuntimeError: Traceback (most recent call last):
  File "/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/pipeline/plugins/multiproc.py", line 69, in run_node
    result['result'] = node.run(updatehash=updatehash)
  File "/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 471, in run
    result = self._run_interface(execute=True)
  File "/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 555, in _run_interface
    return self._run_command(execute)
  File "/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/pipeline/engine/nodes.py", line 635, in _run_command
    result = self._interface.run(cwd=outdir)
  File "/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/interfaces/base/core.py", line 523, in run
    outputs = self.aggregate_outputs(runtime)
  File "/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/interfaces/base/core.py", line 597, in aggregate_outputs
    predicted_outputs = self._list_outputs()
  File "/home/hstojic/.pyenv/nipy/local/lib/python2.7/site-packages/nipype/interfaces/spm/model.py", line 283, in _list_outputs
    outtype = 'nii' if '12' in self.version.split('.')[0] else 'img'
AttributeError: 'NoneType' object has no attribute 'split'

hstojic avatar Feb 21 '19 12:02 hstojic

@hstojic - that particular error is because for some reason it cannot determine spm version: self.version

satra avatar Feb 21 '19 12:02 satra

hi @hstojic - is this ready for another review? anything I can do to help?

mgxd avatar Mar 27 '19 17:03 mgxd

To my understanding, @satra is trying to inquire with @gllmflndn about enabling it for SPM8.

Otherwise, I would be fine with the solution as is, we can simply state it will work only with SPM12 where that option exists.

hstojic avatar Mar 28 '19 08:03 hstojic

@satra @gllmflndn Just a bump on this one. Any news?

effigies avatar Sep 05 '19 02:09 effigies

Is there any news on this pull request? I've been applying this patch to my nipype installation because this option is very useful.

carolfs avatar Feb 16 '21 19:02 carolfs

I didn't find the change in last version nipype 1.7.0. Is it discarded or some bugs or another way to excute?

YukunQu avatar Jan 25 '22 08:01 YukunQu

This option is so useful. Hoping it will be added to nipype soon.

carolfs avatar Jul 07 '22 17:07 carolfs