nipype.algorithms.misc module¶
Miscellaneous algorithms.
AddCSVColumn¶
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_file (a pathlike object or string representing an existing file) – Input comma-separated value (CSV) files.
- Optional Inputs
extra_column_heading (a string) – New heading to add for the added field.
extra_field (a string) – New field to add to each row. This is useful for saving the group or subject ID in the file.
out_file (a pathlike object or string representing a file) – Output filename for merged CSV file. (Nipype default value:
extra_heading.csv
)- Outputs
csv_file (a pathlike object or string representing a file) – Output CSV file containing columns .
AddCSVRow¶
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_file (a pathlike object or string representing a file) – Input comma-separated value (CSV) files.
- Optional Inputs
_outputs (a dictionary with keys which are any value and with values which are any value) – (Nipype default value:
{}
)- Outputs
csv_file (a pathlike object or string representing a file) – Output CSV file containing rows .
AddNoise¶
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_file (a pathlike object or string representing an existing file) – Input image that will be corrupted with noise.
- Optional Inputs
in_mask (a pathlike object or string representing an existing file) – Input mask, voxels outside this mask will be considered background.
out_file (a pathlike object or string representing a file) – Desired output filename.
snr (a float) – Desired output SNR in dB. (Nipype default value:
10.0
)- Outputs
out_file (a 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¶
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_file (a boolean) – Calculate a median file for each Nifti. (Nipype default value:
False
)- Outputs
median_files (a list of items which are a pathlike object or string representing an existing file) – One or more median images.
CalculateNormalizedMoments¶
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
moment (an integer) – Define which moment should be calculated, 3 for skewness, 4 for kurtosis.
timeseries_file (a pathlike object or string representing an existing file) – Text file with timeseries in columns and timepoints in rows, whitespace separated.
- Outputs
moments (a list of items which are a float) – Moments.
CreateNifti¶
Bases: BaseInterface
Creates a nifti volume
- Mandatory Inputs
data_file (a pathlike object or string representing an existing file) – ANALYZE img file.
header_file (a pathlike object or string representing an existing file) – Corresponding ANALYZE hdr file.
- Optional Inputs
affine (an array) – Affine transformation array.
- Outputs
nifti_file (a pathlike object or string representing an existing file)
Distance¶
Bases: Distance
Calculates distance between two volumes.
Deprecated since version 0.10.0: Use
nipype.algorithms.metrics.Distance
instead.
- Mandatory Inputs
volume1 (a pathlike object or string representing an existing file) – Has to have the same dimensions as volume2.
volume2 (a pathlike object or string representing an existing file) – Has to have the same dimensions as volume1.
- Optional Inputs
mask_volume (a 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 Euclidian distance between the Center of Gravity of volume1 and CoGs of volume2 “eucl_mean”: mean Euclidian minimum distance of all volume2 voxels to volume1 “eucl_wmean”: mean Euclidian minimum distance of all volume2 voxels to volume1 weighted by their values “eucl_max”: maximum over minimum Euclidian 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,))
FuzzyOverlap¶
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_ref (a list of items which are a pathlike object or string representing an existing file) – Reference image. Requires the same dimensions as in_tst.
in_tst (a 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_mask (a pathlike object or string representing an existing file) – Calculate overlap only within mask.
out_file (a 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_fdi (a list of items which are a float) – Array containing the fDIs of each computed class.
class_fji (a list of items which are a float) – Array containing the fJIs of each computed class.
dice (a float) – Fuzzy Dice Index (fDI), all the classes.
jaccard (a float) – Fuzzy Jaccard Index (fJI), all the classes.
Gunzip¶
Bases: BaseInterface
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_file (a pathlike object or string representing an existing file)
- Outputs
out_file (a pathlike object or string representing an existing file)
Matlab2CSV¶
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_file (a pathlike object or string representing an existing file) – Input MATLAB .mat file.
- Optional Inputs
reshape_matrix (a 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)
MergeCSVFiles¶
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_files (a list of items which are a pathlike object or string representing an existing file) – Input comma-separated value (CSV) files.
- Optional Inputs
column_headings (a 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_heading (a string) – New heading to add for the added field.
extra_field (a string) – New field to add to each row. This is useful for saving the group or subject ID in the file.
out_file (a pathlike object or string representing a file) – Output filename for merged CSV file. (Nipype default value:
merged.csv
)row_heading_title (a string) – Column heading for the row headings added. (Nipype default value:
label
)row_headings (a 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_file (a pathlike object or string representing a file) – Output CSV file containing columns .
MergeROIs¶
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_reference (a pathlike object or string representing an existing file) – Reference file.
- Outputs
merged_file (a pathlike object or string representing an existing file) – The recomposed file.
ModifyAffine¶
Bases: BaseInterface
Left multiplies the affine matrix with a specified values. Saves the volume as a nifti file.
- Mandatory Inputs
volumes (a list of items which are a pathlike object or string representing an existing file) – Volumes which affine matrices will be modified.
- Optional Inputs
transformation_matrix (an array with shape (4, 4)) – Transformation matrix that will be left multiplied by the affine matrix. (Nipype default value:
(<bound method AbstractArray.copy_default_value of <traits.trait_numeric.Array object at 0x7f3c748696d0>>, (array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]),), None)
)- Outputs
transformed_volumes (a list of items which are a pathlike object or string representing a file)
NormalizeProbabilityMapSet¶
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_files (a list of items which are a pathlike object or string representing an existing file) – Normalized maps.
Overlap¶
Bases: Overlap
Calculates various overlap measures between two maps.
Deprecated since version 0.10.0: Use
nipype.algorithms.metrics.Overlap
instead.
- Mandatory Inputs
bg_overlap (a boolean) – Consider zeros as a label. (Nipype default value:
False
)vol_units (‘voxel’ or ‘mm’) – Units for volumes. (Nipype default value:
voxel
)volume1 (a pathlike object or string representing an existing file) – Has to have the same dimensions as volume2.
volume2 (a pathlike object or string representing an existing file) – Has to have the same dimensions as volume1.
- Optional Inputs
mask_volume (a pathlike object or string representing an existing file) – Calculate overlap only within this mask.
out_file (a 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
dice (a float) – Averaged dice index.
diff_file (a pathlike object or string representing an existing file) – Error map of differences.
jaccard (a float) – Averaged jaccard index.
labels (a list of items which are an integer) – Detected labels.
roi_di (a list of items which are a float) – The Dice index (DI) per ROI.
roi_ji (a list of items which are a float) – The Jaccard index (JI) per ROI.
roi_voldiff (a list of items which are a float) – Volume differences of ROIs.
volume_difference (a float) – Averaged volume difference.
PickAtlas¶
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
atlas (a pathlike object or string representing an existing file) – Location of the atlas that will be used.
labels (an 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_size (an 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_file (a pathlike object or string representing a file) – Where to store the output mask.
- Outputs
mask_file (a pathlike object or string representing an existing file) – Output mask file.
SimpleThreshold¶
Bases: BaseInterface
Applies a threshold to input volumes
- Mandatory Inputs
threshold (a float) – Volumes to be thresholdedeverything below this value will be set to zero.
volumes (a list of items which are a pathlike object or string representing an existing file) – Volumes to be thresholded.
- Outputs
thresholded_volumes (a list of items which are a pathlike object or string representing an existing file) – Thresholded volumes.
SplitROIs¶
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_file (a pathlike object or string representing an existing file) – File to be splitted.
- Optional Inputs
in_mask (a pathlike object or string representing an existing file) – Only process files inside mask.
roi_size (a tuple of the form: (an integer, an integer, an integer)) – Desired ROI size.
- Outputs
out_files (a list of items which are a pathlike object or string representing an existing file) – The resulting ROIs.
out_index (a list of items which are a pathlike object or string representing an existing file) – Arrays keeping original locations.
out_masks (a list of items which are a pathlike object or string representing an existing file) – A mask indicating valid values.
TSNR¶
Bases: TSNR
Deprecated since version 0.12.1: Use
nipype.algorithms.confounds.TSNR
instead
- Mandatory Inputs
in_file (a 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_file (a pathlike object or string representing a file) – Input file after detrending. (Nipype default value:
detrend.nii.gz
)mean_file (a pathlike object or string representing a file) – Output mean file. (Nipype default value:
mean.nii.gz
)regress_poly (an integer >= 1) – Remove polynomials.
stddev_file (a pathlike object or string representing a file) – Output tSNR file. (Nipype default value:
stdev.nii.gz
)tsnr_file (a pathlike object or string representing a file) – Output tSNR file. (Nipype default value:
tsnr.nii.gz
)- Outputs
detrended_file (a pathlike object or string representing a file) – Detrended input file.
mean_file (a pathlike object or string representing an existing file) – Mean image file.
stddev_file (a pathlike object or string representing an existing file) – Std dev image file.
tsnr_file (a 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