alignment - Linear and non-linear analysis methods

neural.alignment.affine_align(dset_from, dset_to, skull_strip=True, mask=None, suffix='_aff', prefix=None, cost=None, epi=False, resample='wsinc5', grid_size=None, opts=[])[source]

interface to 3dAllineate to align anatomies and EPIs

neural.alignment.affine_apply(dset_from, affine_1D, master, affine_suffix='_aff', interp='NN', inverse=False, prefix=None)[source]

apply the 1D file from a previously aligned dataset Applies the matrix in affine_1D to dset_from and makes the final grid look like the dataset master using the interpolation method interp. If inverse is True, will apply the inverse of affine_1D instead

neural.alignment.align_epi(anatomy, epis, suffix='_al', base=3, skull_strip=True)[source]

[[currently in progress]]: a simple replacement for the align_epi_anat.py script, because I’ve found it to be unreliable, in my usage

neural.alignment.align_epi_anat(anatomy, epi_dsets, skull_strip_anat=True)[source]

aligns epis to anatomy using align_epi_anat.py script

Epi_dsets:can be either a string or list of strings of the epi child datasets
Skull_strip_anat:
 if True, anatomy will be skull-stripped using the default method

The default output suffix is “_al”

neural.alignment.convert_coord(coord_from, matrix_file, base_to_aligned=True)[source]

Takes an XYZ array (in DICOM coordinates) and uses the matrix file produced by 3dAllineate to transform it. By default, the 3dAllineate matrix transforms from base to aligned space; to get the inverse transform set base_to_aligned to False

neural.alignment.motion_from_params(param_file, motion_file, individual=True, rms=True)[source]

calculate a motion regressor from the params file given by 3dAllineate

Basically just calculates the rms change in the translation and rotation components. Returns the 6 motion vector (if individual is True) and the RMS difference (if rms is True).

neural.alignment.qwarp_align(dset_from, dset_to, skull_strip=True, mask=None, affine_suffix='_aff', suffix='_qwarp', prefix=None)[source]

aligns dset_from to dset_to using 3dQwarp

Will run 3dSkullStrip (unless skull_strip is False), 3dUnifize, 3dAllineate, and then 3dQwarp. This method will add suffixes to the input dataset for the intermediate files (e.g., _ss, _u). If those files already exist, it will assume they were intelligently named, and use them as is

Skull_strip:If True/False, turns skull-stripping of both datasets on/off. If a string matching dset_from or dset_to, will only skull-strip the given dataset
Mask:Applies the given mask to the alignment. Because of the nature of the alignment algorithms, the mask is always applied to the dset_to. If this isn’t what you want, you need to reverse the transform and re-apply it (e.g., using qwarp_invert() and qwarp_apply()). If the dset_to dataset is skull-stripped, the mask will also be resampled to match the dset_to grid.
Affine_suffix:Suffix applied to dset_from to name the new dataset, as well as the .1D file.
Suffix:Suffix applied to the final dset_from dataset. An additional file with the additional suffix _WARP will be created containing the parameters (e.g., with the default _qwarp suffix, the parameters will be in a file with the suffix _qwarp_WARP)
Prefix:Alternatively to suffix, explicitly give the full output filename

The output affine dataset and 1D, as well as the output of qwarp are named by adding the given suffixes (affine_suffix and qwarp_suffix) to the dset_from file

If skull_strip is a string instead of True/False, it will only skull strip the given dataset instead of both of them

# TODO: currently does not work with +tlrc datasets because the filenames get mangled

neural.alignment.qwarp_apply(dset_from, dset_warp, affine=None, warp_suffix='_warp', master='WARP', interp=None, prefix=None)[source]

applies the transform from a previous qwarp

Uses the warp parameters from the dataset listed in dset_warp (usually the dataset name ends in _WARP) to the dataset dset_from. If a .1D file is given in the affine parameter, it will be applied simultaneously with the qwarp.

If the parameter interp is given, will use as interpolation method, otherwise it will just use the default (currently wsinc5)

Output dataset with have the warp_suffix suffix added to its name

neural.alignment.qwarp_epi(dset, align_subbrick=5, suffix='_qwal', prefix=None)[source]

aligns an EPI time-series using 3dQwarp

Very expensive and not efficient at all, but it can produce pretty impressive alignment for EPI time-series with significant distortions due to motion

neural.alignment.qwarp_invert(warp_param_dset, output_dset, affine_1Dfile=None)[source]

inverts a qwarp (defined in warp_param_dset) (and concatenates affine matrix affine_1Dfile if given) outputs the inverted warp + affine to output_dset

neural.alignment.skullstrip_template(dset, template, prefix=None, suffix=None, dilate=0)[source]

Takes the raw anatomy dset, aligns it to a template brain, and applies a templated skullstrip. Should produce fairly reliable skullstrips as long as there is a decent amount of normal brain and the overall shape of the brain is normal-ish

neural.alignment.volreg(dset, suffix='_volreg', base=3, tshift=3, dfile_suffix='_volreg.1D')[source]

simple interface to 3dvolreg

Suffix:suffix to add to dset for volreg’ed file
Base:either a number or dset[#] of the base image to register to
Tshift:if a number, then tshift ignoring that many images, if None then don’t tshift
Dfile_suffix:suffix to add to dset to save the motion parameters to