How to use the nipype.interfaces.base.traits function in nipype

To help you get started, we’ve selected a few nipype examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nipy / nipype / nipype / interfaces / fsl / maths.py View on Github external
position=4,
        desc="dimension to index max across")


class MaxnImage(MathsCommand):
    """Use fslmaths to generate an image of index of max across
    a given dimension.

    """
    input_spec = MaxnImageInput
    _suffix = "_maxn"


class MinImageInput(MathsInput):

    dimension = traits.Enum(
        "T",
        "X",
        "Y",
        "Z",
        usedefault=True,
        argstr="-%smin",
        position=4,
        desc="dimension to min across")


class MinImage(MathsCommand):
    """Use fslmaths to generate a minimum image across a given dimension.

    """
    input_spec = MinImageInput
    _suffix = "_min"
github APPIAN-PET / APPIAN / nipype.bk / interfaces / minc / info.py View on Github external
return outputs






class StatsOutput(TraitedSpec):
    out_file = traits.Any(desc='Infos ouput')

class StatsInput(MINCCommandInputSpec):
    in_file = File(position=-1, argstr="%s", exists=True, mandatory=True, desc="image to operate on")
    out_file = File(desc="Output Json file")

    opt_string = traits.Str(argstr="%s", mandatory=True, desc="Option defining the infos to print out")
    quiet = traits.Bool(argstr="-quiet", usedefault=True, default_value=True, desc="Overwrite output file")
      
class StatsCommand(MINCCommand):
    _cmd = "mincstats"
    input_spec = StatsInput
    output_spec = StatsOutput

    def aggregate_outputs(self, runtime=None, needed_outputs=None):
        outputs = self._outputs()
        outfile = os.path.join(os.getcwd(), 'stat_result.pck')
        # outfile = os.path.join(os.getcwd(), 'stat_result.json')

        if runtime is None:
            try:
                out_stats = load_json(self.inputs.out_file)
            except IOError:
                return self.run().outputs
github nipy / nipype / nipype / interfaces / camino / connectivity.py View on Github external
requires=['tract_stat'])

    targetname_file = File(
        exists=True,
        argstr='-targetnamefile %s',
        desc=
        ('Optional names of targets. This file should contain one entry per line, '
         'with the target intensity followed by the name, separated by white space. '
         'For example: '
         '  1  some_brain_region '
         '  2     some_other_region '
         'These names will be used in the output. The names themselves should not '
         'contain spaces or commas. The labels may be in any order but the output '
         'matrices will be ordered by label intensity.'))

    tract_stat = traits.Enum(
        "mean",
        "min",
        "max",
        "sum",
        "median",
        "var",
        argstr='-tractstat %s',
        units='NA',
        desc=("Tract statistic to use. See TractStats for other options."),
        requires=['scalar_file'],
        xor=['tract_prop'])

    tract_prop = traits.Enum(
        "length",
        "endpointsep",
        argstr='-tractstat %s',
github nipy / nipype / nipype / algorithms / modelgen.py View on Github external
delattr(runinfo, 'amplitudes')
        info.append(runinfo)
    return info


class SpecifyModelInputSpec(BaseInterfaceInputSpec):
    subject_info = InputMultiPath(
        Bunch,
        mandatory=True,
        xor=['subject_info', 'event_files'],
        desc='Bunch or List(Bunch) subject-specific '
        'condition information. see '
        ':ref:`SpecifyModel` or '
        'SpecifyModel.__doc__ for details')
    event_files = InputMultiPath(
        traits.List(File(exists=True)),
        mandatory=True,
        xor=['subject_info', 'event_files'],
        desc='List of event description files 1, 2 or 3 '
        'column format corresponding to onsets, '
        'durations and amplitudes')
    realignment_parameters = InputMultiPath(
        File(exists=True),
        desc='Realignment parameters returned '
        'by motion correction algorithm',
        copyfile=False)
    parameter_source = traits.Enum(
        "SPM",
        "FSL",
        "AFNI",
        "FSFAST",
        "NIPY",
github FCP-INDI / C-PAC / CPAC / utils / interfaces / function.py View on Github external
from builtins import str, bytes
import inspect

from nipype import logging
from nipype.interfaces.base import (traits, DynamicTraitedSpec, Undefined, isdefined,
                    BaseInterfaceInputSpec)
from nipype.interfaces.io import IOBase, add_traits
from nipype.utils.filemanip import ensure_list
from nipype.utils.functions import getsource, create_function_from_source

iflogger = logging.getLogger('nipype.interface')


class FunctionInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
    function_str = traits.Str(mandatory=True, desc='code for function')


class Function(IOBase):
    """Runs arbitrary function as an interface

    Examples
    --------

    >>> func = 'def func(arg1, arg2=5): return arg1 + arg2'
    >>> fi = Function(input_names=['arg1', 'arg2'], output_names=['out'])
    >>> fi.inputs.function_str = func
    >>> res = fi.run(arg1=1)
    >>> res.outputs.out
    6

    """
github nipy / nipype / nipype / interfaces / dipy / base.py View on Github external
if "variable" in dipy_type and "string" in dipy_type:
        return traits.ListStr, is_mandatory
    elif "variable" in dipy_type and "int" in dipy_type:
        return traits.ListInt, is_mandatory
    elif "variable" in dipy_type and "float" in dipy_type:
        return traits.ListFloat, is_mandatory
    elif "variable" in dipy_type and "bool" in dipy_type:
        return traits.ListBool, is_mandatory
    elif "variable" in dipy_type and "complex" in dipy_type:
        return traits.ListComplex, is_mandatory
    elif "string" in dipy_type and not is_file:
        return traits.Str, is_mandatory
    elif "string" in dipy_type and is_file:
        return File, is_mandatory
    elif "int" in dipy_type:
        return traits.Int, is_mandatory
    elif "float" in dipy_type:
        return traits.Float, is_mandatory
    elif "bool" in dipy_type:
        return traits.Bool, is_mandatory
    elif "complex" in dipy_type:
        return traits.Complex, is_mandatory
    else:
        msg = "Error during convert_to_traits_type({0}).".format(dipy_type) + \
              "Unknown DIPY type."
        raise IOError(msg)
github poldracklab / niworkflows / niworkflows / interfaces / confounds.py View on Github external
1.5,
        usedefault=True,
        desc="Minimum standardised DVARS threshold for flagging a frame as " "a spike.",
    )
    header_prefix = traits.Str(
        "motion_outlier",
        usedefault=True,
        desc="Prefix for spikes in the output TSV header",
    )
    lags = traits.List(
        traits.Int,
        value=[0],
        usedefault=True,
        desc="Relative indices of lagging frames to flag for " "each flagged frame",
    )
    minimum_contiguous = traits.Either(
        None,
        traits.Int,
        usedefault=True,
        desc="Minimum number of contiguous volumes required to avoid "
        "flagging as a spike",
    )
    concatenate = traits.Bool(
        True,
        usedefault=True,
        desc="Indicates whether to concatenate spikes to existing confounds "
        "or return spikes only",
    )
    output_format = traits.Enum(
        "spikes", "mask", usedefault=True, desc="Format of output (spikes or mask)"
    )
    output_file = File(desc="Output path")
github nbraingroup / fmridenoise / fmridenoise / interfaces / bids.py View on Github external
raise MissingFile(f"{file1.path} has no corresponding file. "
                          f"Entities {entity_f1} and {entity_f2} should match.")


class MissingFile(IOError):
    pass


class BIDSGrabInputSpec(BaseInterfaceInputSpec):
    bids_dir = Directory(
        exists=True,
        mandatory=True,
        desc='BIDS dataset root directory'
    )
    derivatives = traits.Either(
        traits.Str, traits.List(Str),
        default='fmriprep',
        usedefault=True,
        mandatory=False,
        desc='Specifies which derivatives to to index'
    )
    task = InputMultiObject(
        Str,
        mandatory=False,
        desc='Names of tasks to denoise'
    )
    session = InputMultiObject(
        Str,
        mandatory=False,
        desc='Names of sessions to denoise'
    )
    subject = InputMultiObject(
github nipy / nipype / nipype / interfaces / semtools / registration / specialized.py View on Github external
_outputs_filenames = {
        "outputVolume": "outputVolume.nii",
        "outputCheckerboardVolume": "outputCheckerboardVolume.nii",
        "outputDisplacementFieldVolume": "outputDisplacementFieldVolume.nrrd",
    }
    _redirect_x = False


class BRAINSTransformFromFiducialsInputSpec(CommandLineInputSpec):
    fixedLandmarks = InputMultiPath(
        traits.List(traits.Float(), minlen=3, maxlen=3),
        desc="Ordered list of landmarks in the fixed image",
        argstr="--fixedLandmarks %s...",
    )
    movingLandmarks = InputMultiPath(
        traits.List(traits.Float(), minlen=3, maxlen=3),
        desc="Ordered list of landmarks in the moving image",
        argstr="--movingLandmarks %s...",
    )
    saveTransform = traits.Either(
        traits.Bool,
        File(),
        hash_files=False,
        desc="Save the transform that results from registration",
        argstr="--saveTransform %s",
    )
    transformType = traits.Enum(
        "Translation",
        "Rigid",
        "Similarity",
        desc="Type of transform to produce",
        argstr="--transformType %s",
github nipy / nipype / nipype / interfaces / freesurfer / preprocess.py View on Github external
distance = traits.Int(argstr="--distance %d", desc="N3 -distance option")
    no_rescale = traits.Bool(
        argstr="--no-rescale",
        desc="do not rescale so that global mean of output == input global mean",
    )
    mask = File(
        exists=True,
        argstr="--mask %s",
        desc="brainmask volume. Input can be any format accepted by mri_convert.",
    )
    transform = File(
        exists=True,
        argstr="--uchar %s",
        desc="tal.xfm. Use mri_make_uchar instead of conforming",
    )
    stop = traits.Float(
        argstr="--stop %f",
        desc="Convergence threshold below which iteration stops (suggest 0.01 to 0.0001)",
    )
    shrink = traits.Int(
        argstr="--shrink %d", desc="Shrink parameter for finer sampling (default is 4)"
    )


class MNIBiasCorrectionOutputSpec(TraitedSpec):
    out_file = File(exists=True, desc="output volume")


class MNIBiasCorrection(FSCommand):
    """ Wrapper for nu_correct, a program from the Montreal Neurological Insitute (MNI)
    used for correcting intensity non-uniformity (ie, bias fields). You must have the
    MNI software installed on your system to run this. See [www.bic.mni.mcgill.ca/software/N3]