How to use the nipype.interfaces.base.isdefined 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 / preprocess.py View on Github external
def _parse_inputs(self, skip=None):
        if skip is None:
            skip = []

        input_phase = isdefined(self.inputs.phasemap_in_file)
        input_vsm = isdefined(self.inputs.shift_in_file)
        input_fmap = isdefined(self.inputs.fmap_in_file)

        if not input_phase and not input_vsm and not input_fmap:
            raise RuntimeError(
                (
                    "Either phasemap_in_file, shift_in_file or fmap_in_file must "
                    "be set."
                )
            )

        if not isdefined(self.inputs.in_file):
            skip += ["unwarped_file", "warped_file"]
        else:
            if self.inputs.forward_warping:
                skip += ["unwarped_file"]
                trait_spec = self.inputs.trait("warped_file")
                trait_spec.name_template = "%s_warped"
github APPIAN-PET / APPIAN / Extra / mincants.py View on Github external
if isdefined( self.inputs.restore_state ) : reg.inputs.restore_state= self.inputs.restore_state
		if isdefined( self.inputs.initial_moving_transform ) : reg.inputs.initial_moving_tr =self.inputs.initial_moving_tr
		if isdefined( self.inputs.invert_initial_moving_transform ) : reg.inputs.invert_initial_moving_tr = self.inputs.invert_initial_moving_tr
		if isdefined( self.inputs.initial_moving_transform_com ) : reg.inputs.initial_moving_transform_com= self.inputs.initial_moving_transform_com
		if isdefined( self.inputs.metric_item_trait  ) : reg.inputs.metric_item_trait= self.inputs.metric_item_trait
		if isdefined( self.inputs.metric_stage_trait ) : reg.inputs.metric_stage_trait= self.inputs.metric_stage_trait
		if isdefined( self.inputs.metric ) : reg.inputs.metric= self.inputs.metric
		if isdefined( self.inputs.metric_weight_item_trait ) : reg.inputs.metric_weight_item_trait= self.inputs.metric_weight_item_trait
		if isdefined( self.inputs.metric_weight_stage_trait) : reg.inputs.metric_weight_stage_trait= self.inputs.metric_weight_stage_trait
		if isdefined( self.inputs.metric_weight ) : reg.inputs.metric_weight= self.inputs.metric_weight
		if isdefined( self.inputs.radius_bins_item_trait) : reg.inputs.radius_bins_item_trait= self.inputs.radius_bins_item_trait
		if isdefined( self.inputs.radius_bins_stage_trait ) : reg.inputs.radius_bins_stage_trait= self.inputs.radius_bins_stage_trait
		if isdefined( self.inputs.radius_or_number_of_bins ) : reg.inputs.radius_or_number_of_bins= self.inputs.radius_or_number_of_bins
		if isdefined( self.inputs.sampling_strategy_item_trait ) : reg.inputs.sampling_strategy_item_trait= self.inputs.sampling_strategy_item_trait
		if isdefined( self.inputs.sampling_strategy_stage_trait) : reg.inputs.sampling_strategy_stage_trait= self.inputs.sampling_strategy_stage_trait
		if isdefined( self.inputs.sampling_strategy) : reg.inputs.sampling_strategy= self.inputs.sampling_strategy
		if isdefined( self.inputs.sampling_percentage_item_trait ) : reg.inputs.sampling_percentage_item_trait= self.inputs.sampling_percentage_item_trait
		if isdefined( self.inputs.sampling_percentage_stage_trait) : reg.inputs.sampling_percentage_stage_trait= self.inputs.sampling_percentage_stage_trait
		if isdefined( self.inputs.sampling_percentage ) : reg.inputs.sampling_percentage= self.inputs.sampling_percentage
		if isdefined( self.inputs.use_estimate_learning_rate_once ) : reg.inputs.use_estimate_learning_rate_once= self.inputs.use_estimate_learning_rate_once
		if isdefined( self.inputs.use_histogram_matching) : reg.inputs.use_histogram_matching= self.inputs.use_histogram_matching
		if isdefined( self.inputs.interpolation) : reg.inputs.interpolation= self.inputs.interpolation
		if isdefined( self.inputs.interpolation_parameters) : reg.inputs.interpolation_parameters= self.inputs.interpolation_parameters
		if isdefined( self.inputs.write_composite_transform ) : reg.inputs.write_composite_transform= self.inputs.write_composite_transform
		if isdefined( self.inputs.collapse_output_transforms) : reg.inputs.collapse_output_transforms= self.inputs.collapse_output_transforms
		if isdefined( self.inputs.initialize_transforms_per_stage ) : reg.inputs.initialize_transforms_per_stage= self.inputs.initialize_transforms_per_stage
		if isdefined( self.inputs.float ) : reg.inputs.float= self.inputs.float
		if isdefined( self.inputs.transform_parameters) : reg.inputs.transform_parameters= self.inputs.transform_parameters
		if isdefined( self.inputs.restrict_deformation ) : reg.inputs.restrict_deformation= self.inputs.restrict_deformation
		if isdefined( self.inputs.number_of_iterations ) : reg.inputs.number_of_iterations= self.inputs.number_of_iterations
		if isdefined( self.inputs.smoothing_sigmas ) : reg.inputs.smoothing_sigmas= self.inputs.smoothing_sigmas
		if isdefined( self.inputs.sigma_units) : reg.inputs.sigma_units= self.inputs.sigma_units
github nipy / nipype / nipype / interfaces / io.py View on Github external
def _list_outputs(self):
        """Execute this module.
        """
        import MySQLdb

        if isdefined(self.inputs.config):
            conn = MySQLdb.connect(
                db=self.inputs.database_name, read_default_file=self.inputs.config
            )
        else:
            conn = MySQLdb.connect(
                host=self.inputs.host,
                user=self.inputs.username,
                passwd=self.inputs.password,
                db=self.inputs.database_name,
            )
        c = conn.cursor()
        c.execute(
            "REPLACE INTO %s (" % self.inputs.table_name
            + ",".join(self._input_names)
            + ") VALUES ("
            + ",".join(["%s"] * len(self._input_names))
github LTS5 / cmp_nipype / cmp / stages / diffusion / tracking.py View on Github external
def _list_outputs(self):
        outputs = self.output_spec().get()
        if not isdefined(self.inputs.out_dir):
            out_dir = self._gen_filename("out_dir")
        else:
            out_dir = self.inputs.out_dir

        # handle seeds-to-target output files
        if isdefined(self.inputs.target_masks):
            outputs['matrix'] = os.path.abspath('matrix_seeds_to_all_targets')
        return outputs
github nipy / nipype / nipype / interfaces / ants / registration.py View on Github external
def _get_outputfilenames(self, inverse=False):
        output_filename = None
        if not inverse:
            if isdefined(self.inputs.output_warped_image) and \
                    self.inputs.output_warped_image:
                output_filename = self.inputs.output_warped_image
                if isinstance(output_filename, bool):
                    output_filename = '%s_Warped.nii.gz' % self.inputs.output_transform_prefix
            return output_filename
        inv_output_filename = None
        if isdefined(self.inputs.output_inverse_warped_image) and \
                self.inputs.output_inverse_warped_image:
            inv_output_filename = self.inputs.output_inverse_warped_image
            if isinstance(inv_output_filename, bool):
                inv_output_filename = '%s_InverseWarped.nii.gz' % self.inputs.output_transform_prefix
        return inv_output_filename
github nipy / nipype / nipype / algorithms / misc.py View on Github external
def __setattr__(self, key, value):
        if key not in self.copyable_trait_names():
            if not isdefined(value):
                super(AddCSVRowInputSpec, self).__setattr__(key, value)
            self._outputs[key] = value
        else:
            if key in self._outputs:
                self._outputs[key] = value
            super(AddCSVRowInputSpec, self).__setattr__(key, value)
github nipy / nipype / nipype / interfaces / freesurfer / utils.py View on Github external
def _gen_outfilename(self):
        if isdefined(self.inputs.out_file):
            return self.inputs.out_file
        elif isdefined(self.inputs.annot_file):
            _, name, ext = split_filename(self.inputs.annot_file)
        elif isdefined(self.inputs.parcstats_file):
            _, name, ext = split_filename(self.inputs.parcstats_file)
        elif isdefined(self.inputs.label_file):
            _, name, ext = split_filename(self.inputs.label_file)
        elif isdefined(self.inputs.scalarcurv_file):
            _, name, ext = split_filename(self.inputs.scalarcurv_file)
        elif isdefined(self.inputs.functional_file):
            _, name, ext = split_filename(self.inputs.functional_file)
        elif isdefined(self.inputs.in_file):
            _, name, ext = split_filename(self.inputs.in_file)

        return name + ext + "_converted." + self.inputs.out_datatype
github nipy / nipype / nipype / interfaces / ants / segmentation.py View on Github external
def _format_arg(self, name, trait_spec, value):
        if ((name == 'output_image') and
            (self.inputs.save_bias or isdefined(self.inputs.bias_image))):
            bias_image = self._gen_filename('bias_image')
            output = self._gen_filename('output_image')
            newval = '[ %s, %s ]' % (output, bias_image)
            return trait_spec.argstr % newval

        if name == 'bspline_fitting_distance':
            if isdefined(self.inputs.bspline_order):
                newval = '[ %g, %d ]' % (value, self.inputs.bspline_order)
            else:
                newval = '[ %g ]' % value
            return trait_spec.argstr % newval

        if name == 'n_iterations':
            if isdefined(self.inputs.convergence_threshold):
                newval = '[ %s, %g ]' % (
                    self._format_xarray([str(elt) for elt in value]),
github nipy / nipype / nipype / interfaces / fsl / preprocess.py View on Github external
outputs = self.output_spec().get()
        outputs['out_file'] = self._gen_outfilename()
        if ((isdefined(self.inputs.mesh) and self.inputs.mesh) or
                (isdefined(self.inputs.surfaces) and self.inputs.surfaces)):
            outputs['meshfile'] = self._gen_fname(outputs['out_file'],
                                                  suffix='_mesh.vtk',
                                                  change_ext=False)
        if (isdefined(self.inputs.mask) and self.inputs.mask) or \
                (isdefined(self.inputs.reduce_bias) and
                 self.inputs.reduce_bias):
            outputs['mask_file'] = self._gen_fname(outputs['out_file'],
                                                   suffix='_mask')
        if isdefined(self.inputs.outline) and self.inputs.outline:
            outputs['outline_file'] = self._gen_fname(outputs['out_file'],
                                                      suffix='_overlay')
        if isdefined(self.inputs.surfaces) and self.inputs.surfaces:
            outputs['inskull_mask_file'] = self._gen_fname(outputs['out_file'],
                                                           suffix='_inskull_mask')
            outputs['inskull_mesh_file'] = self._gen_fname(outputs['out_file'],
                                                           suffix='_inskull_mesh')
            outputs[
                'outskull_mask_file'] = self._gen_fname(outputs['out_file'],
                                                        suffix='_outskull_mask')
            outputs[
                'outskull_mesh_file'] = self._gen_fname(outputs['out_file'],
                                                        suffix='_outskull_mesh')
            outputs['outskin_mask_file'] = self._gen_fname(outputs['out_file'],
                                                           suffix='_outskin_mask')
            outputs['outskin_mesh_file'] = self._gen_fname(outputs['out_file'],
                                                           suffix='_outskin_mesh')
            outputs['skull_mask_file'] = self._gen_fname(outputs['out_file'],
                                                         suffix='_skull_mask')
github nipy / nipype / nipype / interfaces / niftyreg / regutils.py View on Github external
def _gen_filename(self, name):
        if name == 'out_file':
            if isdefined(self.inputs.make_aff_input):
                return self._gen_fname(
                    'matrix', suffix=self._suffix, ext='.txt')

            if isdefined(self.inputs.comp_input) and \
               isdefined(self.inputs.comp_input2):
                _, bn1, ext1 = split_filename(self.inputs.comp_input)
                _, _, ext2 = split_filename(self.inputs.comp_input2)
                if ext1 in ['.nii', '.nii.gz', '.hdr', '.img', '.img.gz'] or \
                   ext2 in ['.nii', '.nii.gz', '.hdr', '.img', '.img.gz']:
                    return self._gen_fname(
                        bn1, suffix=self._suffix, ext='.nii.gz')
                else:
                    return self._gen_fname(bn1, suffix=self._suffix, ext=ext1)

            if isdefined(self.inputs.flirt_2_nr_input):
                return self._gen_fname(
                    self.inputs.flirt_2_nr_input[0],
                    suffix=self._suffix,
                    ext='.txt')

            input_to_use = self._find_input()