nipype.algorithms.misc module

Miscellaneous algorithms.

AddCSVColumn

Link to code

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() 
in_filea pathlike object or string representing an existing file

Input comma-separated value (CSV) files.

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)

csv_filea pathlike object or string representing a file

Output CSV file containing columns .

AddCSVRow

Link to code

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() 
in_filea pathlike object or string representing a file

Input comma-separated value (CSV) files.

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

(Nipype default value: {})

csv_filea pathlike object or string representing a file

Output CSV file containing rows .

AddNoise

Link to code

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() 
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.

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)

out_filea pathlike object or string representing an existing file

Corrupted image.

AddNoise.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)

CalculateMedian

Link to code

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() 

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)

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

One or more median images.

CalculateNormalizedMoments

Link to code

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() 
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.

momentsa list of items which are a float

Moments.

CreateNifti

Link to code

Bases: BaseInterface

Creates a nifti volume

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.

affinean array

Affine transformation array.

nifti_file : a pathlike object or string representing an existing file

Distance

Link to code

Bases: Distance

Calculates distance between two volumes.

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

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.

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)

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

FuzzyOverlap

Link to code

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.

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.

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)

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.

Gunzip

Link to code

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')
in_filea pathlike object or string representing an existing file

File to (de)compress.

mode‘decompress’

Decompress or compress. (Nipype default value: decompress)

out_file : a pathlike object or string representing a file

Gzip

Link to code

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')
in_filea pathlike object or string representing an existing file

File to (de)compress.

mode‘compress’ or ‘decompress’

Compress or decompress. (Nipype default value: compress)

out_file : a pathlike object or string representing a file

Matlab2CSV

Link to code

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() 
in_filea pathlike object or string representing an existing file

Input MATLAB .mat file.

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)

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

MergeCSVFiles

Link to code

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() 
in_filesa list of items which are a pathlike object or string representing an existing file

Input comma-separated value (CSV) files.

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).

csv_filea pathlike object or string representing a file

Output CSV file containing columns .

MergeROIs

Link to code

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() 

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.

merged_filea pathlike object or string representing an existing file

The recomposed file.

ModifyAffine

Link to code

Bases: BaseInterface

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

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

Volumes which affine matrices will be modified.

transformation_matrixan array with shape (4, 4)

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

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

NormalizeProbabilityMapSet

Link to code

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() 

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.

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

Normalized maps.

Overlap

Link to code

Bases: Overlap

Calculates various overlap measures between two maps.

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

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.

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)

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.

PickAtlas

Link to code

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).

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.

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.

mask_filea pathlike object or string representing an existing file

Output mask file.

SimpleThreshold

Link to code

Bases: BaseInterface

Applies a threshold to input volumes

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.

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

Thresholded volumes.

SplitROIs

Link to code

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() 
in_filea pathlike object or string representing an existing file

File to be split.

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.

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.

TSNR

Link to code

Bases: TSNR

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

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.

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)

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