Warning: This document is for an old version of niworkflows. The main version is master.

niworkflows.interfaces.freesurfer module

FreeSurfer tools interfaces.

class niworkflows.interfaces.freesurfer.FSDetectInputs(from_file=None, resource_monitor=None, **inputs)[source]

Bases: nipype.interfaces.base.core.SimpleInterface

input_spec

alias of niworkflows.interfaces.freesurfer._FSDetectInputsInputSpec

output_spec

alias of niworkflows.interfaces.freesurfer._FSDetectInputsOutputSpec

class niworkflows.interfaces.freesurfer.FSInjectBrainExtracted(from_file=None, resource_monitor=None, **inputs)[source]

Bases: nipype.interfaces.base.core.SimpleInterface

input_spec

alias of niworkflows.interfaces.freesurfer._FSInjectBrainExtractedInputSpec

output_spec

alias of niworkflows.interfaces.freesurfer._FSInjectBrainExtractedOutputSpec

class niworkflows.interfaces.freesurfer.MakeMidthickness(**inputs)[source]

Bases: nipype.interfaces.freesurfer.utils.MRIsExpand

Variation on MRIsExpand that checks for an existing midthickness/graymid surface.

mris_expand is an expensive operation, so this avoids re-running it when the working directory is lost. If users provide their own midthickness/graymid file, we assume they have created it correctly.

property cmdline

command plus any arguments (args) validates arguments and generates command line

input_spec

alias of niworkflows.interfaces.freesurfer._MakeMidthicknessInputSpec

class niworkflows.interfaces.freesurfer.MedialNaNs(from_file=None, resource_monitor=None, **inputs)[source]

Bases: nipype.interfaces.base.core.SimpleInterface

Convert values on medial wall to NaNs.

input_spec

alias of niworkflows.interfaces.freesurfer._MedialNaNsInputSpec

output_spec

alias of niworkflows.interfaces.freesurfer._MedialNaNsOutputSpec

class niworkflows.interfaces.freesurfer.PatchedBBRegisterRPT(generate_report=False, **kwargs)[source]

Bases: niworkflows.interfaces.freesurfer.TruncateLTA, niworkflows.interfaces.reportlets.registration.BBRegisterRPT

class niworkflows.interfaces.freesurfer.PatchedConcatenateLTA(**inputs)[source]

Bases: niworkflows.interfaces.freesurfer.TruncateLTA, nipype.interfaces.freesurfer.preprocess.ConcatenateLTA

A temporarily patched version of fs.ConcatenateLTA to recover from this bug in FreeSurfer, that was fixed here.

The original fMRIPrep’s issue is found here.

the fix is now done through mixin with TruncateLTA

lta_outputs = ['out_file']
class niworkflows.interfaces.freesurfer.PatchedLTAConvert(command=None, terminal_output=None, **inputs)[source]

Bases: niworkflows.interfaces.freesurfer.TruncateLTA, nipype.interfaces.freesurfer.utils.LTAConvert

LTAconvert is producing a lta file refer as out_lta truncate filename through mixin TruncateLTA

lta_outputs = ('out_lta',)
class niworkflows.interfaces.freesurfer.PatchedMRICoregRPT(generate_report=False, **kwargs)[source]

Bases: niworkflows.interfaces.freesurfer.TruncateLTA, niworkflows.interfaces.reportlets.registration.MRICoregRPT

class niworkflows.interfaces.freesurfer.PatchedRobustRegister(**inputs)[source]

Bases: niworkflows.interfaces.freesurfer.TruncateLTA, nipype.interfaces.freesurfer.preprocess.RobustRegister

lta_outputs = ('out_reg_file', 'half_source_xfm', 'half_targ_xfm')
class niworkflows.interfaces.freesurfer.RefineBrainMask(from_file=None, resource_monitor=None, **inputs)[source]

Bases: nipype.interfaces.base.core.SimpleInterface

Refine the brain mask implicit in the aseg.mgz file to include possibly missing gray-matter voxels and deep, wide sulci.

input_spec

alias of niworkflows.interfaces.freesurfer._RefineBrainMaskInputSpec

output_spec

alias of niworkflows.interfaces.freesurfer._RefineBrainMaskOutputSpec

class niworkflows.interfaces.freesurfer.StructuralReference(**inputs)[source]

Bases: nipype.interfaces.freesurfer.longitudinal.RobustTemplate

Shortcut RobustTemplate with a copy of the source if a single volume is provided.

Examples

>>> t1w = bids_collect_data(
...     str(datadir / 'ds114'), '01', bids_validate=False)[0]['t1w']
>>> template = StructuralReference()
>>> template.inputs.in_files = t1w
>>> template.inputs.auto_detect_sensitivity = True
>>> template.cmdline  
'mri_robust_template --satit --mov .../sub-01_ses-retest_T1w.nii.gz
    .../sub-01_ses-test_T1w.nii.gz --template mri_robust_template_out.mgz'
property cmdline

command plus any arguments (args) validates arguments and generates command line

class niworkflows.interfaces.freesurfer.TruncateLTA[source]

Bases: object

Truncate long filenames in LTA files.

Mixin to ensure that LTA files do not store overly long paths, which lead to segmentation faults when read by FreeSurfer tools. See the following issues for discussion:

lta_outputs = ('out_lta_file',)
niworkflows.interfaces.freesurfer.detect_inputs(t1w_list, t2w_list=None, flair_list=None, hires_enabled=True)[source]
niworkflows.interfaces.freesurfer.fix_lta_length(lta_file)[source]

Fix the length of the filename field in an LTA file if too long.

Updates file in place.

Examples

No changes are made to a valid transform file:

>>> valid_transform = Path(test_data) / 'valid_transform.lta'
>>> orig_contents = valid_transform.read_text()
>>> fix_lta_length(valid_transform)
False
>>> valid_transform.read_text() == orig_contents
True

Invalid transform files are files with > 255 characters in any line:

>>> invalid_transform = Path(test_data) / 'long_path_transform.lta'
>>> orig_contents = invalid_transform.read_text()
>>> any(len(line) > 255 for line in orig_contents.splitlines(keepends=True))
True
>>> local_copy = Path('invalid.lta')
>>> local_copy.write_text(orig_contents)
2120
>>> fix_lta_length(local_copy)
True
>>> local_copy.read_text() == orig_contents
False
niworkflows.interfaces.freesurfer.grow_mask(anat, aseg, ants_segs=None, ww=7, zval=2.0, bw=4)[source]

Grow mask including pixels that have a high likelihood.

GM tissue parameters are sampled in image patches of ww size. This is inspired on mindboggle’s solution to the problem: https://github.com/nipy/mindboggle/blob/master/mindboggle/guts/segment.py#L1660

niworkflows.interfaces.freesurfer.inject_skullstripped(subjects_dir, subject_id, skullstripped)[source]
niworkflows.interfaces.freesurfer.medial_wall_to_nan(in_file, subjects_dir, den=None, newpath=None)[source]

Convert values on medial wall to NaNs.

niworkflows.interfaces.freesurfer.mri_info(fname, argument)[source]
niworkflows.interfaces.freesurfer.refine_aseg(aseg, ball_size=4)[source]

Refine the aseg.mgz mask of Freesurfer.

First step to reconcile ANTs’ and FreeSurfer’s brain masks. Here, the aseg.mgz mask from FreeSurfer is refined in two steps, using binary morphological operations:

  1. With a binary closing operation the sulci are included into the mask. This results in a smoother brain mask that does not exclude deep, wide sulci.

  2. Fill any holes (typically, there could be a hole next to the pineal gland and the corpora quadrigemina if the great cerebral brain is segmented out).