nipype.algorithms.misc module

Miscellaneous algorithms.

class nipype.algorithms.misc.AddCSVColumn(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Short interface to add an extra column and field to a text file.

Example

>>> from nipype.algorithms import misc
>>> addcol = misc.AddCSVColumn()
>>> addcol.inputs.in_file = 'degree.csv'
>>> addcol.inputs.extra_column_heading = 'group'
>>> addcol.inputs.extra_field = 'male'
>>> addcol.run()

Mandatory Inputs

in_filea pathlike object or string representing an existing file

Input comma-separated value (CSV) files.

Optional Inputs

extra_column_headinga string

New heading to add for the added field.

extra_fielda string

New field to add to each row. This is useful for saving the group or subject ID in the file.

out_filea pathlike object or string representing a file

Output filename for merged CSV file. (Nipype default value: extra_heading.csv)

Outputs

csv_filea pathlike object or string representing a file

Output CSV file containing columns .

class nipype.algorithms.misc.AddCSVRow(infields=None, force_run=True, **kwargs)

Bases: BaseInterface

Simple interface to add an extra row to a CSV file.

Note

Requires pandas

Warning

Multi-platform thread-safe execution is possible with lockfile. Please recall that (1) this module is alpha software; and (2) it should be installed for thread-safe writing. If lockfile is not installed, then the interface is not thread-safe.

Example

>>> from nipype.algorithms import misc
>>> addrow = misc.AddCSVRow()
>>> addrow.inputs.in_file = 'scores.csv'
>>> addrow.inputs.si = 0.74
>>> addrow.inputs.di = 0.93
>>> addrow.inputs.subject_id = 'S400'
>>> addrow.inputs.list_of_values = [ 0.4, 0.7, 0.3 ]
>>> addrow.run()

Mandatory Inputs

in_filea pathlike object or string representing a file

Input comma-separated value (CSV) files.

Optional Inputs

_outputsa dictionary with keys which are any value and with values which are any value

(Nipype default value: {})

Outputs

csv_filea pathlike object or string representing a file

Output CSV file containing rows .

class nipype.algorithms.misc.AddNoise(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Corrupts with noise the input image.

Example

>>> from nipype.algorithms.misc import AddNoise
>>> noise = AddNoise()
>>> noise.inputs.in_file = 'T1.nii'
>>> noise.inputs.in_mask = 'mask.nii'
>>> noise.snr = 30.0
>>> noise.run()

Mandatory Inputs

bg_dist‘normal’ or ‘rayleigh’

Desired noise distribution, currently only normal is implemented. (Nipype default value: normal)

dist‘normal’ or ‘rician’

Desired noise distribution. (Nipype default value: normal)

in_filea pathlike object or string representing an existing file

Input image that will be corrupted with noise.

Optional Inputs

in_maska pathlike object or string representing an existing file

Input mask, voxels outside this mask will be considered background.

out_filea pathlike object or string representing a file

Desired output filename.

snra float

Desired output SNR in dB. (Nipype default value: 10.0)

Outputs

out_filea pathlike object or string representing an existing file

Corrupted image.

gen_noise(image, mask=None, snr_db=10.0, dist='normal', bg_dist='normal')

Generates a copy of an image with a certain amount of added gaussian noise (rayleigh for background in mask)

class nipype.algorithms.misc.CalculateMedian(*args, **kwargs)

Bases: BaseInterface

Computes an average of the median across one or more 4D Nifti timeseries

Example

>>> from nipype.algorithms.misc import CalculateMedian
>>> mean = CalculateMedian()
>>> mean.inputs.in_files = 'functional.nii'
>>> mean.run()

Optional Inputs

in_files : a list of items which are a pathlike object or string representing an existing file median_file : a string

Filename prefix to store median images.

median_per_filea boolean

Calculate a median file for each Nifti. (Nipype default value: False)

Outputs

median_filesa list of items which are a pathlike object or string representing an existing file

One or more median images.

class nipype.algorithms.misc.CalculateNormalizedMoments(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Calculates moments of timeseries.

Example

>>> from nipype.algorithms import misc
>>> skew = misc.CalculateNormalizedMoments()
>>> skew.inputs.moment = 3
>>> skew.inputs.timeseries_file = 'timeseries.txt'
>>> skew.run()

Mandatory Inputs

momentan integer

Define which moment should be calculated, 3 for skewness, 4 for kurtosis.

timeseries_filea pathlike object or string representing an existing file

Text file with timeseries in columns and timepoints in rows, whitespace separated.

Outputs

momentsa list of items which are a float

Moments.

class nipype.algorithms.misc.CreateNifti(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Creates a nifti volume

Mandatory Inputs

data_filea pathlike object or string representing an existing file

ANALYZE img file.

header_filea pathlike object or string representing an existing file

Corresponding ANALYZE hdr file.

Optional Inputs

affinean array

Affine transformation array.

Outputs

nifti_file : a pathlike object or string representing an existing file

class nipype.algorithms.misc.Distance(**inputs)

Bases: Distance

Calculates distance between two volumes.

Deprecated since version 0.10.0: Use nipype.algorithms.metrics.Distance instead.

Mandatory Inputs

volume1a pathlike object or string representing an existing file

Has to have the same dimensions as volume2.

volume2a pathlike object or string representing an existing file

Has to have the same dimensions as volume1.

Optional Inputs

mask_volumea pathlike object or string representing an existing file

Calculate overlap only within this mask.

method‘eucl_min’ or ‘eucl_cog’ or ‘eucl_mean’ or ‘eucl_wmean’ or ‘eucl_max’

“”eucl_min”: Euclidean distance between two closest points “eucl_cog”: mean Euclidean distance between the Center of Gravity of volume1 and CoGs of volume2 “eucl_mean”: mean Euclidean minimum distance of all volume2 voxels to volume1 “eucl_wmean”: mean Euclidean minimum distance of all volume2 voxels to volume1 weighted by their values “eucl_max”: maximum over minimum Euclidean distances of all volume2 voxels to volume1 (also known as the Hausdorff distance). (Nipype default value: eucl_min)

Outputs

distance : a float histogram : a pathlike object or string representing a file point1 : an array with shape (3,) point2 : an array with shape (3,)

class nipype.algorithms.misc.FuzzyOverlap(**inputs)

Bases: FuzzyOverlap

Calculates various overlap measures between two maps, using a fuzzy definition.

Deprecated since version 0.10.0: Use nipype.algorithms.metrics.FuzzyOverlap instead.

Mandatory Inputs

in_refa list of items which are a pathlike object or string representing an existing file

Reference image. Requires the same dimensions as in_tst.

in_tsta list of items which are a pathlike object or string representing an existing file

Test image. Requires the same dimensions as in_ref.

Optional Inputs

in_maska pathlike object or string representing an existing file

Calculate overlap only within mask.

out_filea pathlike object or string representing a file

Alternative name for resulting difference-map. (Nipype default value: diff.nii)

weighting‘none’ or ‘volume’ or ‘squared_vol’

‘none’: no class-overlap weighting is performed. ‘volume’: computed class-overlaps are weighted by class volume ‘squared_vol’: computed class-overlaps are weighted by the squared volume of the class. (Nipype default value: none)

Outputs

class_fdia list of items which are a float

Array containing the fDIs of each computed class.

class_fjia list of items which are a float

Array containing the fJIs of each computed class.

dicea float

Fuzzy Dice Index (fDI), all the classes.

jaccarda float

Fuzzy Jaccard Index (fJI), all the classes.

class nipype.algorithms.misc.Gunzip(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: Gzip

Gunzip wrapper

>>> from nipype.algorithms.misc import Gunzip
>>> gunzip = Gunzip(in_file='tpms_msk.nii.gz')
>>> res = gunzip.run()
>>> res.outputs.out_file
'.../tpms_msk.nii'
>>> os.unlink('tpms_msk.nii')

Mandatory Inputs

in_filea pathlike object or string representing an existing file

File to (de)compress.

Optional Inputs

mode‘decompress’

Decompress or compress. (Nipype default value: decompress)

Outputs

out_file : a pathlike object or string representing a file

class nipype.algorithms.misc.Gzip(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Gzip wrapper

>>> from nipype.algorithms.misc import Gzip
>>> gzip = Gzip(in_file='tpms_msk.nii.gz', mode="decompress")
>>> res = gzip.run()
>>> res.outputs.out_file
'.../tpms_msk.nii'
>>> gzip = Gzip(in_file='tpms_msk.nii')
>>> res = gzip.run()
>>> res.outputs.out_file
'.../tpms_msk.nii.gz'
>>> os.unlink('tpms_msk.nii')

Mandatory Inputs

in_filea pathlike object or string representing an existing file

File to (de)compress.

Optional Inputs

mode‘compress’ or ‘decompress’

Compress or decompress. (Nipype default value: compress)

Outputs

out_file : a pathlike object or string representing a file

class nipype.algorithms.misc.Matlab2CSV(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Save the components of a MATLAB .mat file as a text file with comma-separated values (CSVs).

CSV files are easily loaded in R, for use in statistical processing. For further information, see cran.r-project.org/doc/manuals/R-data.pdf

Example

>>> from nipype.algorithms import misc
>>> mat2csv = misc.Matlab2CSV()
>>> mat2csv.inputs.in_file = 'cmatrix.mat'
>>> mat2csv.run()

Mandatory Inputs

in_filea pathlike object or string representing an existing file

Input MATLAB .mat file.

Optional Inputs

reshape_matrixa boolean

The output of this interface is meant for R, so matrices will be reshaped to vectors by default. (Nipype default value: True)

Outputs

csv_files : a list of items which are a pathlike object or string representing a file

class nipype.algorithms.misc.MergeCSVFiles(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Merge several CSV files into a single CSV file.

This interface is designed to facilitate data loading in the R environment. If provided, it will also incorporate column heading names into the resulting CSV file. CSV files are easily loaded in R, for use in statistical processing. For further information, see cran.r-project.org/doc/manuals/R-data.pdf

Example

>>> from nipype.algorithms import misc
>>> mat2csv = misc.MergeCSVFiles()
>>> mat2csv.inputs.in_files = ['degree.mat','clustering.mat']
>>> mat2csv.inputs.column_headings = ['degree','clustering']
>>> mat2csv.run()

Mandatory Inputs

in_filesa list of items which are a pathlike object or string representing an existing file

Input comma-separated value (CSV) files.

Optional Inputs

column_headingsa list of items which are a string

List of column headings to save in merged CSV file (must be equal to number of input files). If left undefined, these will be pulled from the input filenames.

extra_column_headinga string

New heading to add for the added field.

extra_fielda string

New field to add to each row. This is useful for saving the group or subject ID in the file.

out_filea pathlike object or string representing a file

Output filename for merged CSV file. (Nipype default value: merged.csv)

row_heading_titlea string

Column heading for the row headings added. (Nipype default value: label)

row_headingsa list of items which are a string

List of row headings to save in merged CSV file (must be equal to number of rows in the input files).

Outputs

csv_filea pathlike object or string representing a file

Output CSV file containing columns .

class nipype.algorithms.misc.MergeROIs(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Splits a 3D image in small chunks to enable parallel processing.

ROIs keep time series structure in 4D images.

Example

>>> from nipype.algorithms import misc
>>> rois = misc.MergeROIs()
>>> rois.inputs.in_files = ['roi%02d.nii' % i for i in range(1, 6)]
>>> rois.inputs.in_reference = 'mask.nii'
>>> rois.inputs.in_index = ['roi%02d_idx.npz' % i for i in range(1, 6)]
>>> rois.run()

Optional Inputs

in_files : a list of items which are a pathlike object or string representing an existing file in_index : a list of items which are a pathlike object or string representing an existing file

Array keeping original locations.

in_referencea pathlike object or string representing an existing file

Reference file.

Outputs

merged_filea pathlike object or string representing an existing file

The recomposed file.

class nipype.algorithms.misc.ModifyAffine(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Left multiplies the affine matrix with a specified values. Saves the volume as a nifti file.

Mandatory Inputs

volumesa list of items which are a pathlike object or string representing an existing file

Volumes which affine matrices will be modified.

Optional Inputs

transformation_matrixan array with shape (4, 4)

Transformation matrix that will be left multiplied by the affine matrix.

Outputs

transformed_volumes : a list of items which are a pathlike object or string representing a file

class nipype.algorithms.misc.NormalizeProbabilityMapSet(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Returns the input tissue probability maps (tpms, aka volume fractions).

The tissue probability maps are normalized to sum up 1.0 at each voxel within the mask.

Note

Please recall this is not a spatial normalization algorithm

Example

>>> from nipype.algorithms import misc
>>> normalize = misc.NormalizeProbabilityMapSet()
>>> normalize.inputs.in_files = [ 'tpm_00.nii.gz', 'tpm_01.nii.gz', 'tpm_02.nii.gz' ]
>>> normalize.inputs.in_mask = 'tpms_msk.nii.gz'
>>> normalize.run()

Optional Inputs

in_files : a list of items which are a pathlike object or string representing an existing file in_mask : a pathlike object or string representing an existing file

Masked voxels must sum up 1.0, 0.0 otherwise.

Outputs

out_filesa list of items which are a pathlike object or string representing an existing file

Normalized maps.

class nipype.algorithms.misc.Overlap(**inputs)

Bases: Overlap

Calculates various overlap measures between two maps.

Deprecated since version 0.10.0: Use nipype.algorithms.metrics.Overlap instead.

Mandatory Inputs

bg_overlapa boolean

Consider zeros as a label. (Nipype default value: False)

vol_units‘voxel’ or ‘mm’

Units for volumes. (Nipype default value: voxel)

volume1a pathlike object or string representing an existing file

Has to have the same dimensions as volume2.

volume2a pathlike object or string representing an existing file

Has to have the same dimensions as volume1.

Optional Inputs

mask_volumea pathlike object or string representing an existing file

Calculate overlap only within this mask.

out_filea pathlike object or string representing a file

(Nipype default value: diff.nii)

weighting‘none’ or ‘volume’ or ‘squared_vol’

‘none’: no class-overlap weighting is performed. ‘volume’: computed class-overlaps are weighted by class volume ‘squared_vol’: computed class-overlaps are weighted by the squared volume of the class. (Nipype default value: none)

Outputs

dicea float

Averaged dice index.

diff_filea pathlike object or string representing an existing file

Error map of differences.

jaccarda float

Averaged jaccard index.

labelsa list of items which are an integer

Detected labels.

roi_dia list of items which are a float

The Dice index (DI) per ROI.

roi_jia list of items which are a float

The Jaccard index (JI) per ROI.

roi_voldiffa list of items which are a float

Volume differences of ROIs.

volume_differencea float

Averaged volume difference.

class nipype.algorithms.misc.PickAtlas(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Returns ROI masks given an atlas and a list of labels. Supports dilation and left right masking (assuming the atlas is properly aligned).

Mandatory Inputs

atlasa pathlike object or string representing an existing file

Location of the atlas that will be used.

labelsan integer or a list of items which are an integer

Labels of regions that will be included in the mask. Must be compatible with the atlas used.

Optional Inputs

dilation_sizean integer

Defines how much the mask will be dilated (expanded in 3D). (Nipype default value: 0)

hemi‘both’ or ‘left’ or ‘right’

Restrict the mask to only one hemisphere: left or right. (Nipype default value: both)

output_filea pathlike object or string representing a file

Where to store the output mask.

Outputs

mask_filea pathlike object or string representing an existing file

Output mask file.

class nipype.algorithms.misc.SimpleThreshold(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Applies a threshold to input volumes

Mandatory Inputs

thresholda float

Volumes to be thresholdedeverything below this value will be set to zero.

volumesa list of items which are a pathlike object or string representing an existing file

Volumes to be thresholded.

Outputs

thresholded_volumesa list of items which are a pathlike object or string representing an existing file

Thresholded volumes.

class nipype.algorithms.misc.SplitROIs(from_file=None, resource_monitor=None, ignore_exception=False, **inputs)

Bases: BaseInterface

Splits a 3D image in small chunks to enable parallel processing.

ROIs keep time series structure in 4D images.

Example

>>> from nipype.algorithms import misc
>>> rois = misc.SplitROIs()
>>> rois.inputs.in_file = 'diffusion.nii'
>>> rois.inputs.in_mask = 'mask.nii'
>>> rois.run()

Mandatory Inputs

in_filea pathlike object or string representing an existing file

File to be split.

Optional Inputs

in_maska pathlike object or string representing an existing file

Only process files inside mask.

roi_sizea tuple of the form: (an integer, an integer, an integer)

Desired ROI size.

Outputs

out_filesa list of items which are a pathlike object or string representing an existing file

The resulting ROIs.

out_indexa list of items which are a pathlike object or string representing an existing file

Arrays keeping original locations.

out_masksa list of items which are a pathlike object or string representing an existing file

A mask indicating valid values.

class nipype.algorithms.misc.TSNR(**inputs)

Bases: TSNR

Deprecated since version 0.12.1: Use nipype.algorithms.confounds.TSNR instead

Mandatory Inputs

in_filea list of items which are a pathlike object or string representing an existing file

Realigned 4D file or a list of 3D files.

Optional Inputs

detrended_filea pathlike object or string representing a file

Input file after detrending. (Nipype default value: detrend.nii.gz)

mean_filea pathlike object or string representing a file

Output mean file. (Nipype default value: mean.nii.gz)

regress_polyan integer >= 1

Remove polynomials.

stddev_filea pathlike object or string representing a file

Output tSNR file. (Nipype default value: stdev.nii.gz)

tsnr_filea pathlike object or string representing a file

Output tSNR file. (Nipype default value: tsnr.nii.gz)

Outputs

detrended_filea pathlike object or string representing a file

Detrended input file.

mean_filea pathlike object or string representing an existing file

Mean image file.

stddev_filea pathlike object or string representing an existing file

Std dev image file.

tsnr_filea pathlike object or string representing an existing file

Tsnr image file.

nipype.algorithms.misc.calc_moments(timeseries_file, moment)

Returns nth moment (3 for skewness, 4 for kurtosis) of timeseries (list of values; one per timeseries).

Keyword arguments: timeseries_file – text file with white space separated timepoints in rows

nipype.algorithms.misc.makefmtlist(output_array, typelist, rowheadingsBool, shape, extraheadingBool)
nipype.algorithms.misc.maketypelist(rowheadings, shape, extraheadingBool, extraheading)
nipype.algorithms.misc.merge_csvs(in_list)
nipype.algorithms.misc.merge_rois(in_files, in_idxs, in_ref, dtype=None, out_file=None)

Re-builds an image resulting from a parallelized processing

nipype.algorithms.misc.normalize_tpms(in_files, in_mask=None, out_files=None)

Returns the input tissue probability maps (tpms, aka volume fractions) normalized to sum up 1.0 at each voxel within the mask.

nipype.algorithms.misc.remove_identical_paths(in_files)
nipype.algorithms.misc.replaceext(in_list, ext)
nipype.algorithms.misc.split_rois(in_file, mask=None, roishape=None)

Splits an image in ROIs for parallel processing