niworkflows.interfaces.freesurfer module

FreeSurfer tools interfaces.

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

Bases: SimpleInterface

Mandatory Inputs:

t1w_list (a list of items which are a pathlike object or string representing an existing file) – Input file, part of a BIDS tree.

Optional Inputs:
  • flair_list (a list of items which are a pathlike object or string representing an existing file) – Input file, part of a BIDS tree.

  • hires_enabled (a boolean) – Enable hi-resolution processing. (Nipype default value: True)

  • t2w_list (a list of items which are a pathlike object or string representing an existing file) – Input file, part of a BIDS tree.

Outputs:
  • flair (a pathlike object or string representing a file) – Reference FLAIR image.

  • hires (a boolean) – Enable hi-res processing.

  • mris_inflate (a string) – Mris_inflate argument.

  • t2w (a pathlike object or string representing a file) – Reference T2w image.

  • use_flair (a boolean) – Enable use of FLAIR downstream computation.

  • use_t2w (a boolean) – Enable use of T2w downstream computation.

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

Bases: SimpleInterface

Mandatory Inputs:
  • in_brain (a pathlike object or string representing an existing file) – Input file, part of a BIDS tree.

  • subject_id (a string) – Subject ID.

  • subjects_dir (a pathlike object or string representing a directory) – FreeSurfer SUBJECTS_DIR.

Outputs:
  • subject_id (a string) – Subject ID.

  • subjects_dir (a pathlike object or string representing a directory) – FreeSurfer SUBJECTS_DIR.

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

Bases: MRIsExpand

Wrapped executable: mris_expand.

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.

Mandatory Inputs:
  • distance (a float) – Distance in mm or fraction of cortical thickness. Maps to a command-line argument: %g (position: -2).

  • in_file (a pathlike object or string representing an existing file) – Surface to expand. Maps to a command-line argument: %s (position: -3).

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • dt (a float) – Dt (implicit: 0.25). Maps to a command-line argument: -T %g.

  • environ (a dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’) – Environment variables. (Nipype default value: {})

  • graymid (a list of items which are any value) – Existing graymid/midthickness file.

  • nsurfaces (an integer) – Number of surfacces to write during expansion. Maps to a command-line argument: -N %d.

  • out_name (a string) – Output surface file. If no path, uses directory of in_file. If no path AND missing “lh.” or “rh.”, derive from in_file. Maps to a command-line argument: %s (position: -1). (Nipype default value: expanded)

  • pial (a string) – Name of pial file (implicit: “pial”) If no path, uses directory of in_file If no path AND missing “lh.” or “rh.”, derive from in_file. Maps to a command-line argument: -pial %s.

  • smooth_averages (an integer) – Smooth surface with N iterations after expansion. Maps to a command-line argument: -A %d.

  • sphere (a string) – WARNING: Do not change this trait. (Nipype default value: sphere)

  • spring (a float) – Spring term (implicit: 0.05). Maps to a command-line argument: -S %g.

  • subjects_dir (a pathlike object or string representing an existing directory) – Subjects directory.

  • thickness (a boolean) – Expand by fraction of cortical thickness, not mm. Maps to a command-line argument: -thickness.

  • thickness_name (a string) – Name of thickness file (implicit: “thickness”) If no path, uses directory of in_file If no path AND missing “lh.” or “rh.”, derive from in_file. Maps to a command-line argument: -thickness_name %s.

  • write_iterations (an integer) – Write snapshots of expansion every N iterations. Maps to a command-line argument: -W %d.

Outputs:

out_file (a pathlike object or string representing a file) – Output surface file.

property cmdline

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

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

Bases: SimpleInterface

Convert values on medial wall to NaNs.

Mandatory Inputs:
  • in_file (a pathlike object or string representing an existing file) – Input surface file.

  • subjects_dir (a pathlike object or string representing a directory) – FreeSurfer SUBJECTS_DIR.

Optional Inputs:

density (‘32k’ or ‘59k’ or ‘164k’) – Input file density (fsLR only).

Outputs:

out_file (a pathlike object or string representing a file) – The output surface file.

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

Bases: TruncateLTA, BBRegisterRPT

Wrapped executable: bbregister.

Mandatory Inputs:
  • contrast_type (‘t1’ or ‘t2’ or ‘bold’ or ‘dti’) – Contrast type of image. Maps to a command-line argument: --%s.

  • source_file (a pathlike object or string representing a file) – Source file to be registered. Maps to a command-line argument: --mov %s.

  • subject_id (a string) – Freesurfer subject id. Maps to a command-line argument: --s %s.

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • compress_report (‘auto’ or True or False) – Compress the reportlet using SVGO orWEBP. ‘auto’ - compress if relevant software is installed, True = force,False - don’t attempt to compress. (Nipype default value: auto)

  • dof (6 or 9 or 12) – Number of transform degrees of freedom. Maps to a command-line argument: --%d.

  • environ (a dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’) – Environment variables. (Nipype default value: {})

  • epi_mask (a boolean) – Mask out B0 regions in stages 1 and 2. Maps to a command-line argument: --epi-mask.

  • fsldof (an integer) – Degrees of freedom for initial registration (FSL). Maps to a command-line argument: --fsl-dof %d.

  • init (‘coreg’ or ‘rr’ or ‘spm’ or ‘fsl’ or ‘header’ or ‘best’) – Initialize registration with mri_coreg, spm, fsl, or header. Maps to a command-line argument: --init-%s. Mutually exclusive with inputs: init_reg_file.

  • init_cost_file (a boolean or a pathlike object or string representing a file) – Output initial registration cost file. Maps to a command-line argument: --initcost %s.

  • init_reg_file (a pathlike object or string representing an existing file) – Existing registration file. Maps to a command-line argument: --init-reg %s. Mutually exclusive with inputs: init.

  • intermediate_file (a pathlike object or string representing an existing file) – Intermediate image, e.g. in case of partial FOV. Maps to a command-line argument: --int %s.

  • out_fsl_file (a boolean or a pathlike object or string representing a file) – Write the transformation matrix in FSL FLIRT format. Maps to a command-line argument: --fslmat %s.

  • out_lta_file (a boolean or a pathlike object or string representing a file) – Write the transformation matrix in LTA format. Maps to a command-line argument: --lta %s. (Nipype default value: True)

  • out_reg_file (a pathlike object or string representing a file) – Output registration file. Maps to a command-line argument: --reg %s.

  • out_report (a pathlike object or string representing a file) – Filename for the visual report. (Nipype default value: report.svg)

  • reg_frame (an integer) – 0-based frame index for 4D source file. Maps to a command-line argument: --frame %d. Mutually exclusive with inputs: reg_middle_frame.

  • reg_middle_frame (a boolean) – Register middle frame of 4D source file. Maps to a command-line argument: --mid-frame. Mutually exclusive with inputs: reg_frame.

  • registered_file (a boolean or a pathlike object or string representing a file) – Output warped sourcefile either True or filename. Maps to a command-line argument: --o %s.

  • spm_nifti (a boolean) – Force use of nifti rather than analyze with SPM. Maps to a command-line argument: --spm-nii.

  • subjects_dir (a pathlike object or string representing an existing directory) – Subjects directory.

Outputs:
  • init_cost_file (a pathlike object or string representing an existing file) – Output initial registration cost file.

  • min_cost_file (a pathlike object or string representing an existing file) – Output registration minimum cost file.

  • out_fsl_file (a pathlike object or string representing an existing file) – Output FLIRT-style registration file.

  • out_lta_file (a pathlike object or string representing an existing file) – Output LTA-style registration file.

  • out_reg_file (a pathlike object or string representing an existing file) – Output registration file.

  • out_report (a pathlike object or string representing a file) – Filename for the visual report.

  • registered_file (a pathlike object or string representing an existing file) – Registered and resampled source file.

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

Bases: TruncateLTA, ConcatenateLTA

Wrapped executable: mri_concatenate_lta.

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

Mandatory Inputs:
  • in_lta1 (a pathlike object or string representing an existing file) – Maps some src1 to dst1. Maps to a command-line argument: %s (position: -3).

  • in_lta2 (a pathlike object or string representing an existing file or ‘identity.nofile’) – Maps dst1(src2) to dst2. Maps to a command-line argument: %s (position: -2).

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • environ (a dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’) – Environment variables. (Nipype default value: {})

  • invert_1 (a boolean) – Invert in_lta1 before applying it. Maps to a command-line argument: -invert1.

  • invert_2 (a boolean) – Invert in_lta2 before applying it. Maps to a command-line argument: -invert2.

  • invert_out (a boolean) – Invert output LTA. Maps to a command-line argument: -invertout.

  • out_file (a pathlike object or string representing a file) – The combined LTA maps: src1 to dst2 = LTA2*LTA1. Maps to a command-line argument: %s (position: -1).

  • out_type (‘VOX2VOX’ or ‘RAS2RAS’) – Set final LTA type. Maps to a command-line argument: -out_type %d.

  • subject (a string) – Set subject in output LTA. Maps to a command-line argument: -subject %s.

  • subjects_dir (a pathlike object or string representing an existing directory) – Subjects directory.

  • tal_source_file (a pathlike object or string representing an existing file) – If in_lta2 is talairach.xfm, specify source for talairach. Maps to a command-line argument: -tal %s (position: -5). Requires inputs: tal_template_file.

  • tal_template_file (a pathlike object or string representing an existing file) – If in_lta2 is talairach.xfm, specify template for talairach. Maps to a command-line argument: %s (position: -4). Requires inputs: tal_source_file.

Outputs:

out_file (a pathlike object or string representing a file) – The combined LTA maps: src1 to dst2 = LTA2*LTA1.

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

Bases: TruncateLTA, LTAConvert

Wrapped executable: lta_convert.

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

Mandatory Inputs:
  • in_fsl (a pathlike object or string representing an existing file) – Input transform of FSL type. Maps to a command-line argument: --infsl %s. Mutually exclusive with inputs: in_lta, in_fsl, in_mni, in_reg, in_niftyreg, in_itk.

  • in_itk (a pathlike object or string representing an existing file) – Input transform of ITK type. Maps to a command-line argument: --initk %s. Mutually exclusive with inputs: in_lta, in_fsl, in_mni, in_reg, in_niftyreg, in_itk.

  • in_lta (a pathlike object or string representing an existing file or ‘identity.nofile’) – Input transform of LTA type. Maps to a command-line argument: --inlta %s. Mutually exclusive with inputs: in_lta, in_fsl, in_mni, in_reg, in_niftyreg, in_itk.

  • in_mni (a pathlike object or string representing an existing file) – Input transform of MNI/XFM type. Maps to a command-line argument: --inmni %s. Mutually exclusive with inputs: in_lta, in_fsl, in_mni, in_reg, in_niftyreg, in_itk.

  • in_niftyreg (a pathlike object or string representing an existing file) – Input transform of Nifty Reg type (inverse RAS2RAS). Maps to a command-line argument: --inniftyreg %s. Mutually exclusive with inputs: in_lta, in_fsl, in_mni, in_reg, in_niftyreg, in_itk.

  • in_reg (a pathlike object or string representing an existing file) – Input transform of TK REG type (deprecated format). Maps to a command-line argument: --inreg %s. Mutually exclusive with inputs: in_lta, in_fsl, in_mni, in_reg, in_niftyreg, in_itk.

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • environ (a dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’) – Environment variables. (Nipype default value: {})

  • invert (a boolean) – Maps to a command-line argument: --invert.

  • ltavox2vox (a boolean) – Maps to a command-line argument: --ltavox2vox. Requires inputs: out_lta.

  • out_fsl (a boolean or a pathlike object or string representing a file) – Output transform in FSL format. Maps to a command-line argument: --outfsl %s.

  • out_itk (a boolean or a pathlike object or string representing a file) – Output transform in ITK format. Maps to a command-line argument: --outitk %s.

  • out_lta (a boolean or a pathlike object or string representing a file) – Output linear transform (LTA Freesurfer format). Maps to a command-line argument: --outlta %s.

  • out_mni (a boolean or a pathlike object or string representing a file) – Output transform in MNI/XFM format. Maps to a command-line argument: --outmni %s.

  • out_reg (a boolean or a pathlike object or string representing a file) – Output transform in reg dat format. Maps to a command-line argument: --outreg %s.

  • source_file (a pathlike object or string representing an existing file) – Maps to a command-line argument: --src %s.

  • target_conform (a boolean) – Maps to a command-line argument: --trgconform.

  • target_file (a pathlike object or string representing an existing file) – Maps to a command-line argument: --trg %s.

Outputs:
  • out_fsl (a pathlike object or string representing an existing file) – Output transform in FSL format.

  • out_itk (a pathlike object or string representing an existing file) – Output transform in ITK format.

  • out_lta (a pathlike object or string representing an existing file) – Output linear transform (LTA Freesurfer format).

  • out_mni (a pathlike object or string representing an existing file) – Output transform in MNI/XFM format.

  • out_reg (a pathlike object or string representing an existing file) – Output transform in reg dat format.

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

Bases: TruncateLTA, MRICoregRPT

Wrapped executable: mri_coreg.

Mandatory Inputs:
  • reference_file (a pathlike object or string representing a file) – Reference (target) file. Maps to a command-line argument: --ref %s. Mutually exclusive with inputs: subject_id.

  • source_file (a pathlike object or string representing a file) – Source file to be registered. Maps to a command-line argument: --mov %s.

  • subject_id (a string) – Freesurfer subject ID (implies reference_mask == aparc+aseg.mgz unless otherwise specified). Maps to a command-line argument: --s %s (position: 1). Mutually exclusive with inputs: reference_file. Requires inputs: subjects_dir.

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • brute_force_limit (a float) – Constrain brute force search to +/- lim. Maps to a command-line argument: --bf-lim %g. Mutually exclusive with inputs: no_brute_force.

  • brute_force_samples (an integer) – Number of samples in brute force search. Maps to a command-line argument: --bf-nsamp %d. Mutually exclusive with inputs: no_brute_force.

  • compress_report (‘auto’ or True or False) – Compress the reportlet using SVGO orWEBP. ‘auto’ - compress if relevant software is installed, True = force,False - don’t attempt to compress. (Nipype default value: auto)

  • conform_reference (a boolean) – Conform reference without rescaling. Maps to a command-line argument: --conf-ref.

  • dof (6 or 9 or 12) – Number of transform degrees of freedom. Maps to a command-line argument: --dof %d.

  • environ (a dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’) – Environment variables. (Nipype default value: {})

  • ftol (a float) – Floating-point tolerance (default=1e-7). Maps to a command-line argument: --ftol %e.

  • initial_rotation (a tuple of the form: (a float, a float, a float)) – Initial rotation in degrees. Maps to a command-line argument: --rot %g %g %g.

  • initial_scale (a tuple of the form: (a float, a float, a float)) – Initial scale. Maps to a command-line argument: --scale %g %g %g.

  • initial_shear (a tuple of the form: (a float, a float, a float)) – Initial shear (Hxy, Hxz, Hyz). Maps to a command-line argument: --shear %g %g %g.

  • initial_translation (a tuple of the form: (a float, a float, a float)) – Initial translation in mm (implies no_cras0). Maps to a command-line argument: --trans %g %g %g.

  • linmintol (a float) – Maps to a command-line argument: --linmintol %e.

  • max_iters (an integer >= 1) – Maximum iterations (default: 4). Maps to a command-line argument: --nitersmax %d.

  • no_brute_force (a boolean) – Do not brute force search. Maps to a command-line argument: --no-bf.

  • no_coord_dithering (a boolean) – Turn off coordinate dithering. Maps to a command-line argument: --no-coord-dither.

  • no_cras0 (a boolean) – Do not set translation parameters to align centers of source and reference files. Maps to a command-line argument: --no-cras0.

  • no_intensity_dithering (a boolean) – Turn off intensity dithering. Maps to a command-line argument: --no-intensity-dither.

  • no_smooth (a boolean) – Do not apply smoothing to either reference or source file. Maps to a command-line argument: --no-smooth.

  • num_threads (an integer) – Number of OpenMP threads. Maps to a command-line argument: --threads %d.

  • out_lta_file (a bool or None or a pathlike object or string representing a file) – Output registration file (LTA format). Maps to a command-line argument: --lta %s. (Nipype default value: True)

  • out_params_file (a bool or None or a pathlike object or string representing a file) – Output parameters file. Maps to a command-line argument: --params %s.

  • out_reg_file (a bool or None or a pathlike object or string representing a file) – Output registration file (REG format). Maps to a command-line argument: --regdat %s.

  • out_report (a pathlike object or string representing a file) – Filename for the visual report. (Nipype default value: report.svg)

  • ref_fwhm (a float) – Apply smoothing to reference file. Maps to a command-line argument: --ref-fwhm.

  • reference_mask (a bool or None or a string) – Mask reference volume with given mask, or None if False. Maps to a command-line argument: --ref-mask %s (position: 2).

  • saturation_threshold (0.0 <= a floating point number <= 100.0) – Saturation threshold (default=9.999). Maps to a command-line argument: --sat %g.

  • sep (a list of from 1 to 2 items which are any value) – Set spatial scales, in voxels (default [2, 4]). Maps to a command-line argument: --sep %s....

  • source_mask (a string) – Mask source file with given mask. Maps to a command-line argument: --mov-mask.

  • source_oob (a boolean) – Count source voxels that are out-of-bounds as 0. Maps to a command-line argument: --mov-oob.

  • subjects_dir (a pathlike object or string representing an existing directory) – FreeSurfer SUBJECTS_DIR. Maps to a command-line argument: --sd %s.

Outputs:
  • out_lta_file (a pathlike object or string representing an existing file) – Output LTA-style registration file.

  • out_params_file (a pathlike object or string representing an existing file) – Output parameters file.

  • out_reg_file (a pathlike object or string representing an existing file) – Output registration file.

  • out_report (a pathlike object or string representing a file) – Filename for the visual report.

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

Bases: TruncateLTA, RobustRegister

Wrapped executable: mri_robust_register.

Mandatory Inputs:
  • auto_sens (a boolean) – Auto-detect good sensitivity. Maps to a command-line argument: --satit. Mutually exclusive with inputs: outlier_sens.

  • outlier_sens (a float) – Set outlier sensitivity explicitly. Maps to a command-line argument: --sat %.4f. Mutually exclusive with inputs: auto_sens.

  • source_file (a pathlike object or string representing an existing file) – Volume to be registered. Maps to a command-line argument: --mov %s.

  • target_file (a pathlike object or string representing an existing file) – Target volume for the registration. Maps to a command-line argument: --dst %s.

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • environ (a dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’) – Environment variables. (Nipype default value: {})

  • est_int_scale (a boolean) – Estimate intensity scale (recommended for unnormalized images). Maps to a command-line argument: --iscale.

  • force_double (a boolean) – Use double-precision intensities. Maps to a command-line argument: --doubleprec.

  • force_float (a boolean) – Use float intensities. Maps to a command-line argument: --floattype.

  • half_source (a boolean or a pathlike object or string representing a file) – Write source volume mapped to halfway space. Maps to a command-line argument: --halfmov %s.

  • half_source_xfm (a boolean or a pathlike object or string representing a file) – Write transform from source to halfway space. Maps to a command-line argument: --halfmovlta %s.

  • half_targ (a boolean or a pathlike object or string representing a file) – Write target volume mapped to halfway space. Maps to a command-line argument: --halfdst %s.

  • half_targ_xfm (a boolean or a pathlike object or string representing a file) – Write transform from target to halfway space. Maps to a command-line argument: --halfdstlta %s.

  • half_weights (a boolean or a pathlike object or string representing a file) – Write weights volume mapped to halfway space. Maps to a command-line argument: --halfweights %s.

  • high_iterations (an integer) – Max # of times on highest resolution. Maps to a command-line argument: --highit %d.

  • in_xfm_file (a pathlike object or string representing an existing file) – Use initial transform on source. Maps to a command-line argument: --transform.

  • init_orient (a boolean) – Use moments for initial orient (recommended for stripped brains). Maps to a command-line argument: --initorient.

  • iteration_thresh (a float) – Stop iterations when below threshold. Maps to a command-line argument: --epsit %.3f.

  • least_squares (a boolean) – Use least squares instead of robust estimator. Maps to a command-line argument: --leastsquares.

  • mask_source (a pathlike object or string representing an existing file) – Image to mask source volume with. Maps to a command-line argument: --maskmov %s.

  • mask_target (a pathlike object or string representing an existing file) – Image to mask target volume with. Maps to a command-line argument: --maskdst %s.

  • max_iterations (an integer) – Maximum # of times on each resolution. Maps to a command-line argument: --maxit %d.

  • no_init (a boolean) – Skip transform init. Maps to a command-line argument: --noinit.

  • no_multi (a boolean) – Work on highest resolution. Maps to a command-line argument: --nomulti.

  • out_reg_file (a bool or None or a pathlike object or string representing a file) – Registration file; either True or filename. Maps to a command-line argument: --lta %s. (Nipype default value: True)

  • outlier_limit (a float) – Set maximal outlier limit in satit. Maps to a command-line argument: --wlimit %.3f.

  • registered_file (a boolean or a pathlike object or string representing a file) – Registered image; either True or filename. Maps to a command-line argument: --warp %s.

  • subjects_dir (a pathlike object or string representing an existing directory) – Subjects directory.

  • subsample_thresh (an integer) – Subsample if dimension is above threshold size. Maps to a command-line argument: --subsample %d.

  • trans_only (a boolean) – Find 3 parameter translation only. Maps to a command-line argument: --transonly.

  • weights_file (a boolean or a pathlike object or string representing a file) – Weights image to write; either True or filename. Maps to a command-line argument: --weights %s.

  • write_vo2vox (a boolean) – Output vox2vox matrix (default is RAS2RAS). Maps to a command-line argument: --vox2vox.

Outputs:
  • half_source (a pathlike object or string representing an existing file) – Source image mapped to halfway space.

  • half_source_xfm (a pathlike object or string representing an existing file) – Transform file to map source image to halfway space.

  • half_targ (a pathlike object or string representing an existing file) – Target image mapped to halfway space.

  • half_targ_xfm (a pathlike object or string representing an existing file) – Transform file to map target image to halfway space.

  • half_weights (a pathlike object or string representing an existing file) – Weights image mapped to halfway space.

  • out_reg_file (a pathlike object or string representing an existing file) – Output registration file.

  • registered_file (a pathlike object or string representing an existing file) – Output image with registration applied.

  • weights_file (a pathlike object or string representing an existing file) – Image of weights used.

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: SimpleInterface

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

Mandatory Inputs:
  • in_anat (a pathlike object or string representing an existing file) – Input anatomical reference (INU corrected).

  • in_ants (a pathlike object or string representing an existing file) – Brain tissue segmentation generated with antsBrainExtraction.sh.

  • in_aseg (a pathlike object or string representing an existing file) – Input aseg file, in NifTi format.

Outputs:

out_file (a pathlike object or string representing an existing file) – New mask.

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

Bases: RobustTemplate

Wrapped executable: mri_robust_template.

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'
Mandatory Inputs:
  • auto_detect_sensitivity (a boolean) – Auto-detect good sensitivity (recommended for head or full brain scans). Maps to a command-line argument: --satit. Mutually exclusive with inputs: outlier_sensitivity.

  • in_files (a list of items which are a pathlike object or string representing an existing file) – Input movable volumes to be aligned to common mean/median template. Maps to a command-line argument: --mov %s.

  • out_file (a pathlike object or string representing a file) – Output template volume (final mean/median image). Maps to a command-line argument: --template %s. (Nipype default value: mri_robust_template_out.mgz)

  • outlier_sensitivity (a float) – Set outlier sensitivity manually (e.g. “–sat 4.685” ). Higher values mean less sensitivity. Maps to a command-line argument: --sat %.4f. Mutually exclusive with inputs: auto_detect_sensitivity.

Optional Inputs:
  • args (a string) – Additional parameters to the command. Maps to a command-line argument: %s.

  • average_metric (‘median’ or ‘mean’) – Construct template from: 0 Mean, 1 Median (default). Maps to a command-line argument: --average %d.

  • environ (a dictionary with keys which are a bytes or None or a value of class ‘str’ and with values which are a bytes or None or a value of class ‘str’) – Environment variables. (Nipype default value: {})

  • fixed_timepoint (a boolean) – Map everything to init TP# (init TP is not resampled). Maps to a command-line argument: --fixtp.

  • in_intensity_scales (a list of items which are a pathlike object or string representing an existing file) – Use initial intensity scales. Maps to a command-line argument: --iscalein %s.

  • initial_timepoint (an integer) – Use TP# for spacial init (default random), 0: no init. Maps to a command-line argument: --inittp %d.

  • initial_transforms (a list of items which are a pathlike object or string representing an existing file) – Use initial transforms (lta) on source. Maps to a command-line argument: --ixforms %s.

  • intensity_scaling (a boolean) – Allow also intensity scaling (default off). Maps to a command-line argument: --iscale.

  • no_iteration (a boolean) – Do not iterate, just create first template. Maps to a command-line argument: --noit.

  • num_threads (an integer) – Allows for specifying more threads.

  • scaled_intensity_outputs (a list of items which are a pathlike object or string representing a file or a boolean) – Final intensity scales (will activate –iscale). Maps to a command-line argument: --iscaleout %s.

  • subjects_dir (a pathlike object or string representing an existing directory) – Subjects directory.

  • subsample_threshold (an integer) – Subsample if dim > # on all axes (default no subs.). Maps to a command-line argument: --subsample %d.

  • transform_outputs (a list of items which are a pathlike object or string representing a file or a boolean) – Output xforms to template (for each input). Maps to a command-line argument: --lta %s.

Outputs:
  • out_file (a pathlike object or string representing an existing file) – Output template volume (final mean/median image).

  • scaled_intensity_outputs (a list of items which are a pathlike object or string representing an existing file) – Output final intensity scales.

  • transform_outputs (a list of items which are a pathlike object or string representing an existing file) – Output xform files from moving to template.

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