Skip to content

Fix tutorials (continuation of #1036) #2459

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

Merged
merged 55 commits into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
7aee50d
DOC Updated doc/devel/matlab_interface_devel.rst: remove invalid cara…
Jan 30, 2015
c33285a
Merge remote-tracking branch 'upstream/master' into fix_tutorials
Jan 30, 2015
c6d4d06
DOC Fix typo.
Feb 2, 2015
552d06d
DOC Fix typo.
Feb 2, 2015
ee6c25d
DOC reworked devel/matlab_interface_devel.rst: move code to external …
Feb 2, 2015
20a742c
DOC add blank line in matlab examples
Feb 2, 2015
cb62ced
DOC fix literal block issues in nipype/interfaces/fsl/preprocess.py
Feb 3, 2015
32c4409
Merge branch 'fix_tutorials' of https://github.com/duboism/nipype int…
Feb 3, 2015
dbf58c2
DOC updates in users/tutorial_101: move code in external file (and up…
Feb 6, 2015
343389c
DOC correct download sections in devel/matlab_interface_devel.rst
Feb 6, 2015
4af4773
WIP minimal modifications in users/interface_tutorial.rst
Feb 6, 2015
717555e
Merge branch 'master' into fix_tutorials
Feb 6, 2015
7639c66
DOC correct indentation error in doc/index.rst
Feb 6, 2015
d5d344b
DOC correct indentation error in doc/users/config.rst
Feb 6, 2015
54fefed
DOC correct references in doc/devel/devel/cmd_interface_devel.rst
Feb 6, 2015
8b89b73
fix: documentation indentation and highlighting
nicholsn Feb 8, 2015
10b3cc4
Merge pull request #1 from nicholsn/docs/rsfmri-example
duboism Feb 9, 2015
868b248
DOC minor fix in examples/rsfmri_vol_surface_preprocessing_nipy.py
Feb 9, 2015
6d81823
DOC fix formatting in examples/fmri_ants_openfmri.py
Feb 9, 2015
d67d503
DOC PEP8 edits in examples/fmri_ants_openfmri.py
Feb 9, 2015
4f5ee8e
Merge branch 'master' into fix_tutorials
Feb 10, 2015
41b9cd1
Merge branch 'master' into fix_tutorials
Feb 11, 2015
181255e
DOC Added ANTS to the list of wrapped tools.
Feb 11, 2015
e6994e6
Merge branch 'master' into fix_tutorials
Feb 11, 2015
bfb88ba
Revert "DOC Added ANTS to the list of wrapped tools."
Feb 11, 2015
0eb52cf
WIP Updates in examples/fmri_ants_openfmri.py
Feb 13, 2015
a889ad4
Merge branch 'master' of https://github.com/nipy/nipype
Feb 13, 2015
20032a2
Merge branch 'master' into fix_tutorials
Feb 13, 2015
0434e47
Merge branch 'master' of https://github.com/nipy/nipype
Feb 19, 2015
f0c7abd
Merge branch 'master' into fix_tutorials
Feb 19, 2015
e3d49ea
Merge branch 'master' of https://github.com/nipy/nipype
Mar 1, 2015
cb80e24
Merge branch 'master' into fix_tutorials
Mar 1, 2015
346cdc8
DOC Updated doc/devel/matlab_interface_devel.rst: remove invalid cara…
Jan 30, 2015
d2fca1c
DOC Fix typo.
Feb 2, 2015
ef6c57c
DOC reworked devel/matlab_interface_devel.rst: move code to external …
Feb 2, 2015
2027c70
DOC add blank line in matlab examples
Feb 2, 2015
55238c1
DOC fix literal block issues in nipype/interfaces/fsl/preprocess.py
Feb 3, 2015
e652674
DOC updates in users/tutorial_101: move code in external file (and up…
Feb 6, 2015
81fa276
WIP minimal modifications in users/interface_tutorial.rst
Feb 6, 2015
2eeb567
DOC correct indentation error in doc/index.rst
Feb 6, 2015
bc2bce0
DOC correct indentation error in doc/users/config.rst
Feb 6, 2015
0fab2e4
DOC correct references in doc/devel/devel/cmd_interface_devel.rst
Feb 6, 2015
5899dec
fix: documentation indentation and highlighting
nicholsn Feb 8, 2015
1044641
DOC minor fix in examples/rsfmri_vol_surface_preprocessing_nipy.py
Feb 9, 2015
3ff1dbd
DOC PEP8 edits in examples/fmri_ants_openfmri.py
Feb 9, 2015
fd267ef
DOC Added ANTS to the list of wrapped tools.
Feb 11, 2015
941b7ad
Revert "DOC Added ANTS to the list of wrapped tools."
Feb 11, 2015
b4d0eee
WIP Updates in examples/fmri_ants_openfmri.py
Feb 13, 2015
cfb9bc5
Merge branch 'fix_tutorials' of https://github.com/duboism/nipype int…
Sep 14, 2015
8da068c
DOC remove some leftovers.
Sep 15, 2015
611df19
Merge remote-tracking branch 'upstream/master' into fix_tutorials
effigies Feb 21, 2018
75c7b2a
removing tutorials that are not used anymore (not included in the int…
djarecka Feb 22, 2018
42fe6d5
updating fmri_abts example
djarecka Feb 22, 2018
5e13478
after comments from Chris
djarecka Feb 22, 2018
d4b05ea
STY: Whitespace [skip ci]
effigies Feb 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/devel/cmd_interface_devel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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.core.CommandLine>`:

.. testcode::

Expand Down
47 changes: 47 additions & 0 deletions doc/devel/matlab_example1.py
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
54 changes: 54 additions & 0 deletions doc/devel/matlab_example2.py
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
121 changes: 12 additions & 109 deletions doc/devel/matlab_interface_devel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,127 +4,30 @@
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).
This is a minimal script for wrapping MATLAB code. You should replace the MATLAB
code template, and define approriate inputs and outputs.

mlab = MatlabCommand(script=script, mfile=True)
result = mlab.run()
return result.runtime
.. literalinclude:: matlab_example1.py

def _list_outputs(self):
outputs = self._outputs().get()
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
return outputs
.. admonition:: Example source code

You can download :download:`the source code of this example <matlab_example1.py>`.

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

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




By subclassing :class:`nipype.interfaces.matlab.MatlabCommand` for your main
class, and :class:`nipype.interfaces.matlab.MatlabInputSpec` for your input and
output spec, you gain access to some useful MATLAB hooks

.. 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
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* - .. image:: images/nipype_architecture_overview2.png
:width: 100 %

- .. container::

Current neuroimaging software offer users an incredible opportunity to
Expand Down
2 changes: 1 addition & 1 deletion doc/users/function_interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ the string would be
Unlike when using a function object, this input can be set like any other,
meaning that you could write a function that outputs different function
strings depending on some run-time contingencies, and connect that output
the the ``function_str`` input of a downstream Function interface.
the ``function_str`` input of a downstream Function interface.

.. include:: ../links_names.txt
Loading