-
Notifications
You must be signed in to change notification settings - Fork 533
Fix tutorials #1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Fix tutorials #1036
Changes from 70 commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
a1eb1e7
warping meshes
oesteban e3fdae7
Edited CHANGES, added doctets, fixed errors
oesteban 9769e1b
fixed error in doctest
oesteban cf38e49
Added ETSConfig to avoid display errors
oesteban e85d3a2
Updating mesh algorithms to vtk 6
oesteban 7aee50d
DOC Updated doc/devel/matlab_interface_devel.rst: remove invalid cara…
c33285a
Merge remote-tracking branch 'upstream/master' into fix_tutorials
c6d4d06
DOC Fix typo.
552d06d
DOC Fix typo.
ee6c25d
DOC reworked devel/matlab_interface_devel.rst: move code to external …
20a742c
DOC add blank line in matlab examples
cb62ced
DOC fix literal block issues in nipype/interfaces/fsl/preprocess.py
32c4409
Merge branch 'fix_tutorials' of https://github.com/duboism/nipype int…
dbf58c2
DOC updates in users/tutorial_101: move code in external file (and up…
343389c
DOC correct download sections in devel/matlab_interface_devel.rst
4af4773
WIP minimal modifications in users/interface_tutorial.rst
717555e
Merge branch 'master' into fix_tutorials
7639c66
DOC correct indentation error in doc/index.rst
d5d344b
DOC correct indentation error in doc/users/config.rst
54fefed
DOC correct references in doc/devel/devel/cmd_interface_devel.rst
8b89b73
fix: documentation indentation and highlighting
nicholsn 10b3cc4
Merge pull request #1 from nicholsn/docs/rsfmri-example
duboism 868b248
DOC minor fix in examples/rsfmri_vol_surface_preprocessing_nipy.py
6d81823
DOC fix formatting in examples/fmri_ants_openfmri.py
d67d503
DOC PEP8 edits in examples/fmri_ants_openfmri.py
4f5ee8e
Merge branch 'master' into fix_tutorials
41b9cd1
Merge branch 'master' into fix_tutorials
181255e
DOC Added ANTS to the list of wrapped tools.
e6994e6
Merge branch 'master' into fix_tutorials
bfb88ba
Revert "DOC Added ANTS to the list of wrapped tools."
0eb52cf
WIP Updates in examples/fmri_ants_openfmri.py
a889ad4
Merge branch 'master' of https://github.com/nipy/nipype
20032a2
Merge branch 'master' into fix_tutorials
0434e47
Merge branch 'master' of https://github.com/nipy/nipype
f0c7abd
Merge branch 'master' into fix_tutorials
e3d49ea
Merge branch 'master' of https://github.com/nipy/nipype
cb80e24
Merge branch 'master' into fix_tutorials
44b6427
add exception when setting ETS toolkit
oesteban 416757e
Merge branch 'master' into enh/MeshWarp
oesteban efefdb1
fix conflicts
oesteban 75dc4f2
Merge branch 'master' into enh/MeshWarp
oesteban 53d5149
Merge branch 'master' into enh/MeshWarp
oesteban b83a1ec
describe the input displacement field
oesteban b94f007
Merge branch 'master' into enh/MeshWarp
oesteban abd899a
remove unncecessary pass statements
oesteban 22d6d8d
Merge branch 'master' into enh/MeshWarp
oesteban 095fc7c
Merge branch 'master' into enh/MeshWarp
oesteban f03dec0
added support for boolean flags
chrisgorgo 0c9d4ee
Merge remote-tracking branch 'oesteban/enh/MeshWarp'
chrisgorgo 13edf84
fixed tests
chrisgorgo fcd493e
Merge pull request #1212 from chrisfilo/enh/fsl_outliers
satra a33b643
Merge pull request #1213 from chrisfilo/fix/cmd_bool
satra f5c206d
Update .travis.yml
satra 346cdc8
DOC Updated doc/devel/matlab_interface_devel.rst: remove invalid cara…
d2fca1c
DOC Fix typo.
ef6c57c
DOC reworked devel/matlab_interface_devel.rst: move code to external …
2027c70
DOC add blank line in matlab examples
55238c1
DOC fix literal block issues in nipype/interfaces/fsl/preprocess.py
e652674
DOC updates in users/tutorial_101: move code in external file (and up…
81fa276
WIP minimal modifications in users/interface_tutorial.rst
2eeb567
DOC correct indentation error in doc/index.rst
bc2bce0
DOC correct indentation error in doc/users/config.rst
0fab2e4
DOC correct references in doc/devel/devel/cmd_interface_devel.rst
5899dec
fix: documentation indentation and highlighting
nicholsn 1044641
DOC minor fix in examples/rsfmri_vol_surface_preprocessing_nipy.py
3ff1dbd
DOC PEP8 edits in examples/fmri_ants_openfmri.py
fd267ef
DOC Added ANTS to the list of wrapped tools.
941b7ad
Revert "DOC Added ANTS to the list of wrapped tools."
b4d0eee
WIP Updates in examples/fmri_ants_openfmri.py
cfb9bc5
Merge branch 'fix_tutorials' of https://github.com/duboism/nipype int…
8da068c
DOC remove some leftovers.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,11 @@ above example we have used the ``desc`` metadata which holds human readable | |
description of the input. The ``mandatory`` flag forces Nipype to throw an | ||
exception if the input was not set. ``exists`` is a special flag that works only | ||
for ``File traits`` and checks if the provided file exists. More details can be | ||
<<<<<<< HEAD | ||
found at :doc:`interface_specs`. | ||
======= | ||
found at :ref:`interface_specs`. | ||
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. left over? |
||
|
||
The input and output specifications have to be connected to the our example | ||
interface class: | ||
|
@@ -80,7 +84,7 @@ symbols. For an input defined in InputSpec to be included into the executed | |
commandline ``argstr`` has to be included. Additionally inside the main | ||
interface class you need to specify the name of the executable by assigning it | ||
to the ``_cmd`` field. Also the main interface class needs to inherit from | ||
:class:`nipype.interfaces.base.CommandLine`: | ||
:class:`CommandLine <nipype.interfaces.base.CommandLine>`: | ||
|
||
.. testcode:: | ||
|
||
|
@@ -92,7 +96,7 @@ to the ``_cmd`` field. Also the main interface class needs to inherit from | |
There is one more thing we need to take care of. When the executable finishes | ||
processing it will presumably create some output files. We need to know which | ||
files to look for, check if they exist and expose them to whatever node would | ||
like to use them. This is done by implementing ``_list_outputs`` method in the | ||
like to use them. This is done by implementing :func:`_list_outputs <nipype.interfaces.base.BaseInterface._list_outputs>` method in the | ||
main interface class. Basically what it does is assigning the expected output | ||
files to the fields of our output spec: | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from nipype.interfaces.matlab import MatlabCommand | ||
from nipype.interfaces.base import TraitedSpec, \ | ||
BaseInterface, BaseInterfaceInputSpec, File | ||
import os | ||
from string import Template | ||
|
||
|
||
class ConmapTxt2MatInputSpec(BaseInterfaceInputSpec): | ||
in_file = File(exists=True, mandatory=True) | ||
out_file = File('cmatrix.mat', usedefault=True) | ||
|
||
|
||
class ConmapTxt2MatOutputSpec(TraitedSpec): | ||
out_file = File(exists=True) | ||
|
||
|
||
class ConmapTxt2Mat(BaseInterface): | ||
input_spec = ConmapTxt2MatInputSpec | ||
output_spec = ConmapTxt2MatOutputSpec | ||
|
||
def _run_interface(self, runtime): | ||
d = dict(in_file=self.inputs.in_file, | ||
out_file=self.inputs.out_file) | ||
# This is your MATLAB code template | ||
script = Template("""in_file = '$in_file'; | ||
out_file = '$out_file'; | ||
ConmapTxt2Mat(in_file, out_file); | ||
exit; | ||
""").substitute(d) | ||
|
||
# mfile = True will create an .m file with your script and executed. | ||
# Alternatively | ||
# mfile can be set to False which will cause the matlab code to be | ||
# passed | ||
# as a commandline argument to the matlab executable | ||
# (without creating any files). | ||
# This, however, is less reliable and harder to debug | ||
# (code will be reduced to | ||
# a single line and stripped of any comments). | ||
mlab = MatlabCommand(script=script, mfile=True) | ||
result = mlab.run() | ||
return result.runtime | ||
|
||
def _list_outputs(self): | ||
outputs = self._outputs().get() | ||
outputs['out_file'] = os.path.abspath(self.inputs.out_file) | ||
return outputs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from nipype.interfaces.base import traits | ||
from nipype.interfaces.base import TraitedSpec | ||
from nipype.interfaces.matlab import MatlabCommand, MatlabInputSpec | ||
|
||
|
||
class HelloWorldInputSpec(MatlabInputSpec): | ||
name = traits.Str(mandatory=True, | ||
desc='Name of person to say hello to') | ||
|
||
|
||
class HelloWorldOutputSpec(TraitedSpec): | ||
matlab_output = traits.Str() | ||
|
||
|
||
class HelloWorld(MatlabCommand): | ||
"""Basic Hello World that displays Hello <name> in MATLAB | ||
|
||
Returns | ||
------- | ||
|
||
matlab_output : capture of matlab output which may be | ||
parsed by user to get computation results | ||
|
||
Examples | ||
-------- | ||
|
||
>>> hello = HelloWorld() | ||
>>> hello.inputs.name = 'hello_world' | ||
>>> out = hello.run() | ||
>>> print out.outputs.matlab_output | ||
""" | ||
input_spec = HelloWorldInputSpec | ||
output_spec = HelloWorldOutputSpec | ||
|
||
def _my_script(self): | ||
"""This is where you implement your script""" | ||
script = """ | ||
disp('Hello %s Python') | ||
two = 1 + 1 | ||
""" % (self.inputs.name) | ||
return script | ||
|
||
def run(self, **inputs): | ||
# Inject your script | ||
self.inputs.script = self._my_script() | ||
results = super(MatlabCommand, self).run(**inputs) | ||
stdout = results.runtime.stdout | ||
# Attach stdout to outputs to access matlab results | ||
results.outputs.matlab_output = stdout | ||
return results | ||
|
||
def _list_outputs(self): | ||
outputs = self._outputs().get() | ||
return outputs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,127 +4,39 @@ | |
How to wrap a MATLAB script | ||
=========================== | ||
|
||
This is minimal script for wrapping MATLAB code. You should replace the MATLAB | ||
code template, and define approriate inputs and outputs. | ||
|
||
|
||
Example 1 | ||
+++++++++ | ||
|
||
.. testcode:: | ||
|
||
from nipype.interfaces.matlab import MatlabCommand | ||
from nipype.interfaces.base import TraitedSpec, BaseInterface, BaseInterfaceInputSpec, File | ||
import os | ||
from string import Template | ||
|
||
class ConmapTxt2MatInputSpec(BaseInterfaceInputSpec): | ||
in_file = File(exists=True, mandatory=True) | ||
out_file = File('cmatrix.mat', usedefault=True) | ||
|
||
class ConmapTxt2MatOutputSpec(TraitedSpec): | ||
out_file = File(exists=True) | ||
|
||
class ConmapTxt2Mat(BaseInterface): | ||
input_spec = ConmapTxt2MatInputSpec | ||
output_spec = ConmapTxt2MatOutputSpec | ||
|
||
def _run_interface(self, runtime): | ||
d = dict(in_file=self.inputs.in_file, | ||
out_file=self.inputs.out_file) | ||
#this is your MATLAB code template | ||
script = Template("""in_file = ‘$in_file'; | ||
out_file = ‘$out_file'; | ||
ConmapTxt2Mat(in_file, out_file); | ||
exit; | ||
""").substitute(d) | ||
|
||
# mfile = True will create an .m file with your script and executed. | ||
# Alternatively | ||
# mfile can be set to False which will cause the matlab code to be | ||
# passed | ||
# as a commandline argument to the matlab executable | ||
# (without creating any files). | ||
# This, however, is less reliable and harder to debug | ||
# (code will be reduced to | ||
# a single line and stripped of any comments). | ||
|
||
mlab = MatlabCommand(script=script, mfile=True) | ||
result = mlab.run() | ||
return result.runtime | ||
|
||
def _list_outputs(self): | ||
outputs = self._outputs().get() | ||
outputs['out_file'] = os.path.abspath(self.inputs.out_file) | ||
return outputs | ||
|
||
|
||
Example 2 | ||
+++++++++ | ||
|
||
By subclassing **MatlabCommand** for your main class, and **MatlabInputSpec** for your input and output spec, you gain access to some useful MATLAB hooks | ||
|
||
.. testcode:: | ||
|
||
import os | ||
from nipype.interfaces.base import File, traits | ||
from nipype.interfaces.matlab import MatlabCommand, MatlabInputSpec | ||
|
||
|
||
class HelloWorldInputSpec( MatlabInputSpec): | ||
name = traits.Str( mandatory = True, | ||
desc = 'Name of person to say hello to') | ||
|
||
class HelloWorldOutputSpec( MatlabInputSpec): | ||
matlab_output = traits.Str( ) | ||
|
||
class HelloWorld( MatlabCommand): | ||
""" Basic Hello World that displays Hello <name> in MATLAB | ||
|
||
Returns | ||
------- | ||
|
||
matlab_output : capture of matlab output which may be | ||
parsed by user to get computation results | ||
|
||
Examples | ||
-------- | ||
|
||
>>> hello = HelloWorld() | ||
>>> hello.inputs.name = 'hello_world' | ||
>>> out = hello.run() | ||
>>> print out.outputs.matlab_output | ||
""" | ||
input_spec = HelloWorldInputSpec | ||
output_spec = HelloWorldOutputSpec | ||
This is a minimal script for wrapping MATLAB code. You should replace the MATLAB | ||
code template, and define approriate inputs and outputs. | ||
|
||
def _my_script(self): | ||
"""This is where you implement your script""" | ||
script = """ | ||
disp('Hello %s Python') | ||
two = 1 + 1 | ||
"""%(self.inputs.name) | ||
return script | ||
.. literalinclude:: matlab_example1.py | ||
|
||
.. admonition:: Example source code | ||
|
||
def run(self, **inputs): | ||
## inject your script | ||
self.inputs.script = self._my_script() | ||
results = super(MatlabCommand, self).run( **inputs) | ||
stdout = results.runtime.stdout | ||
# attach stdout to outputs to access matlab results | ||
results.outputs.matlab_output = stdout | ||
return results | ||
You can download :download:`the source code of this example <matlab_example1.py>`. | ||
|
||
Example 2 | ||
+++++++++ | ||
|
||
def _list_outputs(self): | ||
outputs = self._outputs().get() | ||
return outputs | ||
By subclassing :class:`nipype.interfaces.matlab.MatlabCommand` for your main class, and :class:`nipype.interfaces.matlab.MatlabInputSpec` for your input spec, you gain access to some useful MATLAB hooks | ||
<<<<<<< HEAD | ||
|
||
.. literalinclude:: matlab_example2.py | ||
|
||
.. admonition:: Example source code | ||
|
||
You can download :download:`the source code of this example <matlab_example2.py>`. | ||
|
||
.. include:: ../links_names.txt | ||
======= | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unresolved conflict? |
||
|
||
.. literalinclude:: matlab_example2.py | ||
|
||
.. admonition:: Example source code | ||
|
||
You can download :download:`the source code of this example <matlab_example2.py>`. | ||
>>>>>>> cb80e24fc2a68758defcb16c7ab70092aa35b693 | ||
|
||
.. include:: ../links_names.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this an accidental change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember having touched that file. So probably an accident. I will reverted this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not comparing properly with master - those changes are already in there. @duboism - could you please close this pull request and send a new one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satra Are you talking about the file .travis.yml or about all the modifications?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, I have just cloned master in a separate directory and the .travis.yml file is identical the the one in this branch.