nipype.interfaces.utility.base module¶
# changing to temporary directories >>> tmp = getfixture(‘tmpdir’) >>> old = tmp.chdir()
- class nipype.interfaces.utility.base.AssertEqual(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)¶
Bases:
BaseInterfaceMandatory Inputs¶
volume1 : a pathlike object or string representing an existing file volume2 : a pathlike object or string representing an existing file
- class nipype.interfaces.utility.base.IdentityInterface(fields=None, mandatory_inputs=True, **inputs)¶
Bases:
IOBaseBasic interface class generates identity mappings
Examples
>>> from nipype.interfaces.utility import IdentityInterface >>> ii = IdentityInterface(fields=['a', 'b'], mandatory_inputs=False) >>> ii.inputs.a <undefined>
>>> ii.inputs.a = 'foo' >>> out = ii._outputs() >>> out.a <undefined>
>>> out = ii.run() >>> out.outputs.a 'foo'
>>> ii2 = IdentityInterface(fields=['a', 'b'], mandatory_inputs=True) >>> ii2.inputs.a = 'foo' >>> out = ii2.run() ValueError: IdentityInterface requires a value for input 'b' because it was listed in 'fields' Interface IdentityInterface failed to run.
- input_spec¶
alias of
DynamicTraitedSpec
- output_spec¶
alias of
DynamicTraitedSpec
- class nipype.interfaces.utility.base.Merge(numinputs=0, **inputs)¶
Bases:
IOBaseBasic interface class to merge inputs into a single list
Merge(1)will merge a list of listsExamples
>>> from nipype.interfaces.utility import Merge >>> mi = Merge(3) >>> mi.inputs.in1 = 1 >>> mi.inputs.in2 = [2, 5] >>> mi.inputs.in3 = 3 >>> out = mi.run() >>> out.outputs.out [1, 2, 5, 3]
>>> merge = Merge(1) >>> merge.inputs.in1 = [1, [2, 5], 3] >>> out = merge.run() >>> out.outputs.out [1, [2, 5], 3]
>>> merge = Merge(1) >>> merge.inputs.in1 = [1, [2, 5], 3] >>> merge.inputs.ravel_inputs = True >>> out = merge.run() >>> out.outputs.out [1, 2, 5, 3]
>>> merge = Merge(1) >>> merge.inputs.in1 = [1, [2, 5], 3] >>> merge.inputs.no_flatten = True >>> out = merge.run() >>> out.outputs.out [[1, [2, 5], 3]]
Optional Inputs¶
- axis‘vstack’ or ‘hstack’
Direction in which to merge, hstack requires same number of elements in each input. (Nipype default value:
vstack)- no_flattena boolean
Append to outlist instead of extending in vstack mode. (Nipype default value:
False)- ravel_inputsa boolean
Ravel inputs when no_flatten is False. (Nipype default value:
False)
Outputs¶
- outa list of items which are any value
Merged output.
- class nipype.interfaces.utility.base.Rename(format_string=None, **inputs)¶
Bases:
SimpleInterface,IOBaseChange the name of a file based on a mapped format string.
To use additional inputs that will be defined at run-time, the class constructor must be called with the format template, and the fields identified will become inputs to the interface.
Additionally, you may set the parse_string input, which will be run over the input filename with a regular expressions search, and will fill in additional input fields from matched groups. Fields set with inputs have precedence over fields filled in with the regexp match.
Examples
>>> from nipype.interfaces.utility import Rename >>> rename1 = Rename() >>> rename1.inputs.in_file = os.path.join(datadir, "zstat1.nii.gz") # datadir is a directory with exemplary files, defined in conftest.py >>> rename1.inputs.format_string = "Faces-Scenes.nii.gz" >>> res = rename1.run() >>> res.outputs.out_file 'Faces-Scenes.nii.gz"
>>> rename2 = Rename(format_string="%(subject_id)s_func_run%(run)02d") >>> rename2.inputs.in_file = os.path.join(datadir, "functional.nii") >>> rename2.inputs.keep_ext = True >>> rename2.inputs.subject_id = "subj_201" >>> rename2.inputs.run = 2 >>> res = rename2.run() >>> res.outputs.out_file 'subj_201_func_run02.nii'
>>> rename3 = Rename(format_string="%(subject_id)s_%(seq)s_run%(run)02d.nii") >>> rename3.inputs.in_file = os.path.join(datadir, "func_epi_1_1.nii") >>> rename3.inputs.parse_string = r"func_(?P<seq>\w*)_.*" >>> rename3.inputs.subject_id = "subj_201" >>> rename3.inputs.run = 2 >>> res = rename3.run() >>> res.outputs.out_file 'subj_201_epi_run02.nii'
Mandatory Inputs¶
- format_stringa string
Python formatting string for output template.
- in_filea pathlike object or string representing an existing file
File to rename.
Optional Inputs¶
- keep_exta boolean
Keep in_file extension, replace non-extension component of name.
- parse_stringa string
Python regexp parse string to define replacement inputs.
- use_fullpatha boolean
Use full path as input to regex parser. (Nipype default value:
False)
Outputs¶
- out_filea pathlike object or string representing an existing file
Softlink to original file with new name.
- input_spec¶
alias of
RenameInputSpec
- class nipype.interfaces.utility.base.RenameInputSpec(**kwargs)¶
Bases:
DynamicTraitedSpec
- class nipype.interfaces.utility.base.Select(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)¶
Bases:
IOBaseBasic interface class to select specific elements from a list
Examples
>>> from nipype.interfaces.utility import Select >>> sl = Select() >>> _ = sl.inputs.trait_set(inlist=[1, 2, 3, 4, 5], index=[3]) >>> out = sl.run() >>> out.outputs.out 4
>>> _ = sl.inputs.trait_set(inlist=[1, 2, 3, 4, 5], index=[3, 4]) >>> out = sl.run() >>> out.outputs.out [4, 5]
Mandatory Inputs¶
- indexa list of items which are an integer
0-based indices of values to choose.
- inlista list of items which are any value
List of values to choose from.
Outputs¶
- outa list of items which are any value
List of selected values.
- class nipype.interfaces.utility.base.Split(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)¶
Bases:
IOBaseBasic interface class to split lists into multiple outputs
Examples
>>> from nipype.interfaces.utility import Split >>> sp = Split() >>> _ = sp.inputs.trait_set(inlist=[1, 2, 3], splits=[2, 1]) >>> out = sp.run() >>> out.outputs.out1 [1, 2]
Mandatory Inputs¶
- inlista list of items which are any value
List of values to split.
- splitsa list of items which are an integer
Number of outputs in each split - should add to number of inputs.
Optional Inputs¶
- squeezea boolean
Unfold one-element splits removing the list. (Nipype default value:
False)
- output_spec¶
alias of
DynamicTraitedSpec