def get_parser():
    # initialize parameters
    # TODO: create a class ParamFmriMoco which inheritates from ParamMoco
    param_default = ParamMoco(group_size=1, metric='MeanSquares', smooth='0')

    # parser initialisation
    parser = SCTArgumentParser(
        description=
        "Motion correction of fMRI data. Some robust features include:\n"
        "  - group-wise (-g)\n"
        "  - slice-wise regularized along z using polynomial function (-p)\n"
        "    (For more info about the method, type: isct_antsSliceRegularizedRegistration)\n"
        "  - masking (-m)\n"
        "  - iterative averaging of target volume\n"
        "\n"
        "The outputs of the motion correction process are:\n"
        "  - the motion-corrected fMRI volumes\n"
        "  - the time average of the corrected fMRI volumes\n"
        "  - a time-series with 1 voxel in the XY plane, for the X and Y motion direction (two separate "
        "files), as required for FSL analysis.\n"
        "  - a TSV file with the slice-wise average of the motion correction for XY (one file), that "
        "can be used for Quality Control.\n")

    mandatory = parser.add_argument_group("\nMANDATORY ARGUMENTS")
    mandatory.add_argument('-i',
                           metavar=Metavar.file,
                           required=True,
                           help="Input data (4D). Example: fmri.nii.gz")
    optional = parser.add_argument_group("\nOPTIONAL ARGUMENTS")
    optional.add_argument("-h",
                          "--help",
                          action="help",
                          help="Show this help message and exit.")
    optional.add_argument(
        '-g',
        metavar=Metavar.int,
        type=int,
        help="Group nvols successive fMRI volumes for more robustness.")
    optional.add_argument(
        '-m',
        metavar=Metavar.file,
        help=
        "Binary mask to limit voxels considered by the registration metric.")
    optional.add_argument(
        '-param',
        metavar=Metavar.list,
        type=list_type(',', str),
        help=
        f"Advanced parameters. Assign value with \"=\"; Separate arguments with \",\".\n"
        f"  - poly [int]: Degree of polynomial function used for regularization along Z. For no regularization "
        f"set to 0. Default={param_default.poly}.\n"
        f"  - smooth [mm]: Smoothing kernel. Default={param_default.smooth}.\n"
        f"  - iter [int]: Number of iterations. Default={param_default.iter}.\n"
        f"  - metric {{MI, MeanSquares, CC}}: Metric used for registration. Default={param_default.metric}.\n"
        f"  - gradStep [float]: Searching step used by registration algorithm. The higher the more deformation "
        f"allowed. Default={param_default.gradStep}.\n"
        f"  - sampling [None or 0-1]: Sampling rate used for registration metric. "
        f"Default={param_default.sampling}.\n"
        f"  - numTarget [int]: Target volume or group (starting with 0). Default={param_default.num_target}.\n"
        f"  - iterAvg [int]: Iterative averaging: Target volume is a weighted average of the "
        f"previously-registered volumes. Default={param_default.iterAvg}.\n")
    optional.add_argument('-ofolder',
                          metavar=Metavar.folder,
                          action=ActionCreateFolder,
                          default='.',
                          help="Output path.")
    optional.add_argument('-x',
                          choices=['nn', 'linear', 'spline'],
                          default='linear',
                          help="Final interpolation.")
    optional.add_argument('-r',
                          metavar=Metavar.int,
                          type=int,
                          choices=[0, 1],
                          default=1,
                          help="Remove temporary files. O = no, 1 = yes")
    optional.add_argument(
        '-v',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1, 2],
        default=1,
        # Values [0, 1, 2] map to logging levels [WARNING, INFO, DEBUG], but are also used as "if verbose == #" in API
        help=
        "Verbosity. 0: Display only errors/warnings, 1: Errors/warnings + info messages, 2: Debug mode"
    )
    optional.add_argument(
        '-qc',
        metavar=Metavar.folder,
        action=ActionCreateFolder,
        help=
        "The path where the quality control generated content will be saved. (Note: "
        "Both '-qc' and '-qc-seg' are required in order to generate a QC report.)"
    )
    optional.add_argument(
        '-qc-seg',
        metavar=Metavar.file,
        help=
        "Segmentation of spinal cord to improve cropping in qc report. (Note: "
        "Both '-qc' and '-qc-seg' are required in order to generate a QC report.)"
    )
    optional.add_argument(
        '-qc-fps',
        metavar=Metavar.float,
        type=float,
        default=3,
        help=
        "This float number is the number of frames per second for the output gif images."
    )
    optional.add_argument(
        '-qc-dataset',
        metavar=Metavar.str,
        help=
        "If provided, this string will be mentioned in the QC report as the dataset the process was run on."
    )
    optional.add_argument(
        '-qc-subject',
        metavar=Metavar.str,
        help=
        "If provided, this string will be mentioned in the QC report as the subject the process was run on."
    )

    return parser
def get_parser():
    # initialize default param
    param_default = Param()
    # parser initialisation
    parser = argparse.ArgumentParser(description=(
        "This function takes an anatomical image and its cord segmentation (binary file), and outputs the "
        "cord segmentation labeled with vertebral level. The algorithm requires an initialization (first disc) and "
        "then performs a disc search in the superior, then inferior direction, using template disc matching based "
        "on mutual information score. The automatic method uses the module implemented in "
        "'spinalcordtoolbox/vertebrae/detect_c2c3.py' to detect the C2-C3 disc.\n"
        "Tips: To run the function with init txt file that includes flags -initz/-initcenter:\n"
        "  sct_label_vertebrae -i t2.nii.gz -s t2_seg-manual.nii.gz  '$(< init_label_vertebrae.txt)'"
    ),
                                     formatter_class=SmartFormatter,
                                     add_help=None,
                                     prog=os.path.basename(__file__).strip(
                                         ".py"))

    mandatory = parser.add_argument_group("\nMANDATORY ARGUMENTS")
    mandatory.add_argument('-i',
                           metavar=Metavar.file,
                           required=True,
                           help="Input image. Example: t2.nii.gz")
    mandatory.add_argument(
        '-s',
        metavar=Metavar.file,
        required=True,
        help="Segmentation of the spinal cord. Example: t2_seg.nii.gz")
    mandatory.add_argument(
        '-c',
        choices=['t1', 't2'],
        required=True,
        help=
        "Type of image contrast. 't2': cord dark / CSF bright. 't1': cord bright / CSF dark"
    )

    optional = parser.add_argument_group("\nOPTIONAL ARGUMENTS")
    optional.add_argument("-h",
                          "--help",
                          action="help",
                          help="Show this help message and exit.")
    optional.add_argument('-t',
                          metavar=Metavar.folder,
                          default=os.path.join(__data_dir__, "PAM50"),
                          help="Path to template.")
    optional.add_argument(
        '-initz',
        metavar=Metavar.list,
        type=list_type(',', int),
        help=
        "R|Initialize using slice number and disc value. Example: 68,4 (slice 68 corresponds to disc C3/C4). "
        "Example: 125,3\n"
        "WARNING: Slice number should correspond to superior-inferior direction (e.g. Z in RPI orientation, but "
        "Y in LIP orientation).")
    optional.add_argument(
        '-initcenter',
        metavar=Metavar.int,
        type=int,
        help=
        "Initialize using disc value centered in the rostro-caudal direction. If the spine is curved, then "
        "consider the disc that projects onto the cord at the center of the z-FOV."
    )
    optional.add_argument(
        '-initfile',
        metavar=Metavar.file,
        help=
        "Initialize labeling by providing a text file which includes either -initz or -initcenter flag."
    )
    optional.add_argument(
        '-initlabel',
        metavar=Metavar.file,
        help=
        "Initialize vertebral labeling by providing a nifti file that has a single disc label. An example of "
        "such file is a single voxel with value '3', which would be located at the posterior tip of C2-C3 disc. "
        "Such label file can be created using: sct_label_utils -i IMAGE_REF -create-viewer 3 ; or by using the "
        "Python module 'detect_c2c3' implemented in 'spinalcordtoolbox/vertebrae/detect_c2c3.py'."
    )
    optional.add_argument(
        '-discfile',
        metavar=Metavar.file,
        help=
        "File with disc labels, which will be used to transform the input segmentation into a vertebral level "
        "file. In that case, there will be no disc detection. The convention for disc labels is the following: "
        "value=3 -> disc C2/C3, value=4 -> disc C3/C4, etc.")
    optional.add_argument('-ofolder',
                          metavar=Metavar.file,
                          action=ActionCreateFolder,
                          default='',
                          help="Output folder.")
    optional.add_argument(
        '-laplacian',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1],
        default=0,
        help=
        "Apply Laplacian filtering. More accurate but could mistake disc depending on anatomy."
    )
    optional.add_argument(
        '-clean-labels',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1],
        default=0,
        help=
        " Clean output labeled segmentation to resemble original segmentation."
    )
    optional.add_argument(
        '-scale-dist',
        metavar=Metavar.float,
        type=float,
        default=1.,
        help=
        "Scaling factor to adjust the average distance between two adjacent intervertebral discs. For example, "
        "if you are dealing with images from pediatric population, the distance should be reduced, so you can "
        "try a scaling factor of about 0.7.")
    optional.add_argument(
        '-param',
        metavar=Metavar.list,
        type=list_type(',', str),
        help=
        f"R|Advanced parameters. Assign value with \"=\"; Separate arguments with \",\"\n"
        f"  - shift_AP [mm]: AP shift of centerline for disc search. Default={param_default.shift_AP}.\n"
        f"  - size_AP [mm]: AP window size for disc search. Default={param_default.size_AP}.\n"
        f"  - size_RL [mm]: RL window size for disc search. Default={param_default.size_RL}.\n"
        f"  - size_IS [mm]: IS window size for disc search. Default={param_default.size_IS}.\n"
        f"  - gaussian_std [mm]: STD of the Gaussian function, centered at the most rostral point of the "
        f"image, and used to weight C2-C3 disk location finding towards the rostral portion of the FOV. Values "
        f"to set between 0.1 (strong weighting) and 999 (no weighting). "
        f"Default={param_default.gaussian_std}.\n")
    optional.add_argument('-r',
                          metavar=Metavar.int,
                          type=int,
                          choices=[0, 1],
                          default=1,
                          help="Remove temporary files.")
    optional.add_argument(
        '-v',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1, 2],
        default=1,
        # Values [0, 1, 2] map to logging levels [WARNING, INFO, DEBUG], but are also used as "if verbose == #" in API
        help=
        "Verbosity. 0: Display only errors/warnings, 1: Errors/warnings + info messages, 2: Debug mode"
    )
    optional.add_argument(
        '-qc',
        metavar=Metavar.folder,
        action=ActionCreateFolder,
        default=param_default.path_qc,
        help=
        "The path where the quality control generated content will be saved.")
    optional.add_argument(
        '-qc-dataset',
        metavar=Metavar.str,
        help=
        "If provided, this string will be mentioned in the QC report as the dataset the process was run on."
    )
    optional.add_argument(
        '-qc-subject',
        metavar=Metavar.str,
        help=
        "If provided, this string will be mentioned in the QC report as the subject the process was run on."
    )

    return parser
Example #3
0
def get_parser():

    param_default = Param()

    # Read .txt files referencing the labels (for extended usage description)
    file_label = os.path.join(param_default.path_label,
                              param_default.file_info_label)
    check_file_exist(file_label, 0)
    default_info_label = open(file_label, 'r')
    label_references = default_info_label.read()
    default_info_label.close()

    description = (
        f"This program extracts metrics (e.g., DTI or MTR) within labels. Labels could be a single file or "
        f"a folder generated with 'sct_warp_template' and containing multiple label files and a label "
        f"description file (info_label.txt). The labels should be in the same space coordinates as the "
        f"input image.\n"
        f"\n"
        f"To list white matter atlas labels: {os.path.basename(__file__)} -f "
        f"{os.path.join(__data_dir__, 'atlas')}\n"
        f"\n"
        f"To compute FA within labels 0, 2 and 3 within vertebral levels C2 to C7 using binary method: "
        f"{os.path.basename(__file__)} -i dti_FA.nii.gz -f label/atlas -l 0,2,3 -v 2:7 -m bin\n"
    )

    if label_references != '':
        description += (
            f"\nTo compute average MTR in a region defined by a single label file (could be binary or 0-1 "
            f"weighted mask) between slices 1 and 4: {os.path.basename(__file__)} -i mtr.nii.gz -f "
            f"my_mask.nii.gz -z 1:4 -m wa\n"
            f"List of labels in {file_label}:\n"
            f"--------------------------------------------------------------------------------------\n"
            f"{label_references}\n"
            f"--------------------------------------------------------------------------------------\n"
        )

    parser = argparse.ArgumentParser(
        description=description,
        formatter_class=SmartFormatter,
        add_help=None,
        prog=os.path.basename(__file__).strip(".py"))
    mandatory = parser.add_argument_group("\nMANDATORY ARGUMENTS")
    mandatory.add_argument(
        '-i',
        metavar=Metavar.file,
        required=True,
        help="Image file to extract metrics from. Example: FA.nii.gz")

    optional = parser.add_argument_group("\nOPTIONAL ARGUMENTS")
    optional.add_argument("-h",
                          "--help",
                          action="help",
                          help="Show this help message and exit.")
    optional.add_argument(
        '-f',
        metavar=Metavar.folder,
        default=os.path.join("label", "atlas"),
        help=(f"Single label file, or folder that contains WM tract labels."
              f"Example: {os.path.join(__data_dir__, 'atlas')}"))
    optional.add_argument(
        '-l',
        metavar=Metavar.str,
        default='',
        help=
        "Label IDs to extract the metric from. Default = all labels. Separate labels with ','. To select a group "
        "of consecutive labels use ':'. Example: 1:3 is equivalent to 1,2,3. Maximum Likelihood (or MAP) is "
        "computed using all tracts, but only values of the selected tracts are reported."
    )
    optional.add_argument(
        '-method',
        choices=['ml', 'map', 'wa', 'bin', 'max'],
        default=param_default.method,
        help="R|Method to extract metrics.\n"
        "  - ml: maximum likelihood (only use with well-defined regions and low noise)\n"
        "    N.B. ONLY USE THIS METHOD WITH THE WHITE MATTER ATLAS! The sum of all tracts should be 1 in "
        "all voxels (the algorithm doesn't normalize the atlas).\n"
        "  - map: maximum a posteriori. Mean priors are estimated by maximum likelihood within three clusters "
        "(white matter, gray matter and CSF). Tract and noise variance are set with flag -p.\n"
        "    N.B. ONLY USE THIS METHOD WITH THE WHITE MATTER ATLAS! The sum of all tracts should be 1 in "
        "all voxels (the algorithm doesn't normalize the atlas).\n"
        "  - wa: weighted average\n"
        "  - bin: binarize mask (threshold=0.5)\n"
        "  - max: for each z-slice of the input data, extract the max value for each slice of the input data."
    )
    optional.add_argument(
        '-append',
        type=int,
        choices=(0, 1),
        default=0,
        help=
        "Whether to append results as a new line in the output csv file instead of overwriting it. 0 = no, 1 = yes"
    )
    optional.add_argument(
        '-combine',
        type=int,
        choices=(0, 1),
        default=0,
        help=
        "Whether to combine multiple labels into a single estimation. 0 = no, 1 = yes"
    )
    optional.add_argument(
        '-o',
        metavar=Metavar.file,
        default=param_default.fname_output,
        help=
        "R|File name of the output result file collecting the metric estimation results. Include the '.csv' "
        "file extension in the file name. Example: extract_metric.csv")
    optional.add_argument(
        '-output-map',
        metavar=Metavar.file,
        default='',
        help=
        "File name for an image consisting of the atlas labels multiplied by the estimated metric values "
        "yielding the metric value map, useful to assess the metric estimation and especially partial volume "
        "effects.")
    optional.add_argument(
        '-z',
        metavar=Metavar.str,
        default=param_default.slices_of_interest,
        help=
        "R|Slice range to estimate the metric from. First slice is 0. Example: 5:23\n"
        "You can also select specific slices using commas. Example: 0,2,3,5,12'"
    )
    optional.add_argument(
        '-perslice',
        type=int,
        choices=(0, 1),
        default=param_default.perslice,
        help=
        "R|Whether to output one metric per slice instead of a single output metric. 0 = no, 1 = yes.\n"
        "Please note that when methods ml or map are used, outputting a single metric per slice and then "
        "averaging them all is not the same as outputting a single metric at once across all slices."
    )
    optional.add_argument(
        '-vert',
        metavar=Metavar.str,
        default=param_default.vertebral_levels,
        help=
        "Vertebral levels to estimate the metric across. Example: 2:9 (for C2 to T2)"
    )
    optional.add_argument(
        '-vertfile',
        metavar=Metavar.file,
        default="./label/template/PAM50_levels.nii.gz",
        help=
        "Vertebral labeling file. Only use with flag -vert. Example: PAM50_levels.nii.gz"
    )
    optional.add_argument(
        '-perlevel',
        type=int,
        metavar=Metavar.int,
        default=0,
        help=
        "R|Whether to output one metric per vertebral level instead of a single output metric. 0 = no, 1 = yes.\n"
        "Please note that this flag needs to be used with the -vert option.")
    optional.add_argument('-v',
                          choices=("0", "1"),
                          default="1",
                          help="Verbose. 0 = nothing, 1 = expanded")

    advanced = parser.add_argument_group("\nFOR ADVANCED USERS")
    advanced.add_argument(
        '-param',
        metavar=Metavar.str,
        default='',
        help=
        "R|Advanced parameters for the 'map' method. Separate with comma. All items must be listed (separated "
        "with comma).\n"
        "  - #1: standard deviation of metrics across labels\n"
        "  - #2: standard deviation of the noise (assumed Gaussian)")
    advanced.add_argument(
        '-fix-label',
        metavar=Metavar.list,
        type=list_type(',', str),
        default='',
        help=
        "When using ML or MAP estimations, if you do not want to estimate the metric in one label and fix its "
        "value to avoid effects on other labels, specify <label_ID>,<metric_value. Example: -fix-label 36,0 "
        "(Fix the CSF value)")
    advanced.add_argument(
        '-norm-file',
        metavar=Metavar.file,
        default='',
        help='Filename of the label by which the user wants to normalize.')
    advanced.add_argument(
        '-norm-method',
        choices=['sbs', 'whole'],
        default='',
        help="R|Method to use for normalization:\n"
        "  - sbs: normalization slice-by-slice\n"
        "  - whole: normalization by the metric value in the whole label for all slices."
    )
    advanced.add_argument(
        '-mask-weighted',
        metavar=Metavar.file,
        default='',
        help=
        "Nifti mask to weight each voxel during ML or MAP estimation. Example: PAM50_wm.nii.gz"
    )
    advanced.add_argument(
        '-discard-neg-val',
        choices=('0', '1'),
        default='0',
        help=
        'Whether to discard voxels with negative value when computing metrics statistics. 0 = no, 1 = yes'
    )

    return parser
Example #4
0
def get_parser():
    # initialize default parameters
    param_default = Param()

    # Initialize the parser
    parser = SCTArgumentParser(
        description="Smooth the spinal cord along its centerline. Steps are:\n"
        "  1) Spinal cord is straightened (using centerline),\n"
        "  2) a Gaussian kernel is applied in the superior-inferior direction,\n"
        "  3) then cord is de-straightened as originally.\n")

    mandatory = parser.add_argument_group("\nMANDATORY ARGUMENTS")
    mandatory.add_argument('-i',
                           metavar=Metavar.file,
                           required=True,
                           help="Image to smooth. Example: data.nii.gz")
    mandatory.add_argument(
        '-s',
        metavar=Metavar.file,
        required=True,
        help=
        "Spinal cord centerline or segmentation. Example: data_centerline.nii.gz"
    )

    optional = parser.add_argument_group("\nOPTIONAL ARGUMENTS")
    optional.add_argument("-h",
                          "--help",
                          action="help",
                          help="Show this help message and exit.")
    optional.add_argument(
        '-smooth',
        metavar=Metavar.list,
        type=list_type(',', float),
        default=[0, 0, 3],
        help=
        "Sigma (standard deviation) of the smoothing Gaussian kernel (in mm). For isotropic smoothing you only "
        "need to specify a value (e.g. 2). For anisotropic smoothing specify a value for each axis, separated "
        "with a comma. The order should follow axes Right-Left, Antero-Posterior, Superior-Inferior "
        "(e.g.: 1,1,3). For no smoothing, set value to 0.")
    optional.add_argument(
        '-algo-fitting',
        metavar=Metavar.str,
        choices=['bspline', 'polyfit'],
        default=param_default.algo_fitting,
        help=
        f"Algorithm for curve fitting. For more information, see sct_straighten_spinalcord."
    )
    optional.add_argument("-o",
                          metavar=Metavar.file,
                          help='Output filename. Example: smooth_sc.nii '),
    optional.add_argument(
        '-r',
        choices=[0, 1],
        default=1,
        help="Whether to remove temporary files. 0 = no, 1 = yes")
    optional.add_argument(
        '-v',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1, 2],
        default=1,
        # Values [0, 1, 2] map to logging levels [WARNING, INFO, DEBUG], but are also used as "if verbose == #" in API
        help=
        "Verbosity. 0: Display only errors/warnings, 1: Errors/warnings + info messages, 2: Debug mode"
    )

    return parser
def get_parser():
    # initialize default parameters
    param_default = Param()

    # Initialize the parser
    parser = argparse.ArgumentParser(
        description="Smooth the spinal cord along its centerline. Steps are:\n"
                    "  1) Spinal cord is straightened (using centerline),\n"
                    "  2) a Gaussian kernel is applied in the superior-inferior direction,\n"
                    "  3) then cord is de-straightened as originally.\n",
        formatter_class=SmartFormatter,
        add_help=None,
        prog=os.path.basename(__file__).strip(".py")
    )

    mandatory = parser.add_argument_group("\nMANDATORY ARGUMENTS")
    mandatory.add_argument(
        '-i',
        metavar=Metavar.file,
        required=True,
        help="Image to smooth. Example: data.nii.gz"
    )
    mandatory.add_argument(
        '-s',
        metavar=Metavar.file,
        required=True,
        help="Spinal cord centerline or segmentation. Example: data_centerline.nii.gz"
    )

    optional = parser.add_argument_group("\nOPTIONAL ARGUMENTS")
    optional.add_argument(
        "-h",
        "--help",
        action="help",
        help="Show this help message and exit."
    )
    optional.add_argument(
        '-smooth',
        metavar=Metavar.list,
        type=list_type(',', float),
        default=[0, 0, 3],
        help="Sigma (standard deviation) of the smoothing Gaussian kernel (in mm). For isotropic smoothing you only "
             "need to specify a value (e.g. 2). For anisotropic smoothing specify a value for each axis, separated "
             "with a comma. The order should follow axes Right-Left, Antero-Posterior, Superior-Inferior "
             "(e.g.: 1,1,3). For no smoothing, set value to 0."
    )
    optional.add_argument(
        '-algo-fitting',
        metavar=Metavar.str,
        choices=['bspline', 'polyfit'],
        default=param_default.algo_fitting,
        help=f"Algorithm for curve fitting. For more information, see sct_straighten_spinalcord."
    )
    optional.add_argument(
        '-r',
        choices=[0, 1],
        default=1,
        help="Whether to remove temporary files. 0 = no, 1 = yes"
    )
    optional.add_argument(
        '-v',
        choices=['0', '1', '2'],
        default='1',
        help="Verbose: 0 = nothing, 1 = classic, 2 = expended"
    )

    return parser
Example #6
0
def get_parser():
    parser = SCTArgumentParser(
        description=
        'Perform mathematical operations on images. Some inputs can be either a number or a 4d image or '
        'several 3d images separated with ","')

    mandatory = parser.add_argument_group("MANDATORY ARGUMENTS")
    mandatory.add_argument("-i",
                           metavar=Metavar.file,
                           help="Input file. Example: data.nii.gz",
                           required=True)
    mandatory.add_argument("-o",
                           metavar=Metavar.file,
                           help='Output file. Example: data_mean.nii.gz',
                           required=True)

    optional = parser.add_argument_group("OPTIONAL ARGUMENTS")
    optional.add_argument("-h",
                          "--help",
                          action="help",
                          help="Show this help message and exit")

    basic = parser.add_argument_group('BASIC OPERATIONS')
    basic.add_argument(
        "-add",
        metavar='',
        nargs="+",
        help=
        'Add following input. Can be a number or multiple images (separated with space).',
        required=False)
    basic.add_argument(
        "-sub",
        metavar='',
        nargs="+",
        help='Subtract following input. Can be a number or an image.',
        required=False)
    basic.add_argument(
        "-mul",
        metavar='',
        nargs="+",
        help=
        'Multiply by following input. Can be a number or multiple images (separated with space).',
        required=False)
    basic.add_argument(
        "-div",
        metavar='',
        nargs="+",
        help='Divide by following input. Can be a number or an image.',
        required=False)
    basic.add_argument('-mean',
                       help='Average data across dimension.',
                       required=False,
                       choices=('x', 'y', 'z', 't'))
    basic.add_argument('-rms',
                       help='Compute root-mean-squared across dimension.',
                       required=False,
                       choices=('x', 'y', 'z', 't'))
    basic.add_argument('-std',
                       help='Compute STD across dimension.',
                       required=False,
                       choices=('x', 'y', 'z', 't'))
    basic.add_argument(
        "-bin",
        type=float,
        metavar=Metavar.float,
        help='Binarize image using specified threshold. Example: 0.5',
        required=False)

    thresholding = parser.add_argument_group("THRESHOLDING METHODS")
    thresholding.add_argument(
        '-otsu',
        type=int,
        metavar=Metavar.int,
        help=
        'Threshold image using Otsu algorithm (from skimage). Specify the number of bins (e.g. 16, 64, 128)',
        required=False)
    thresholding.add_argument(
        "-adap",
        metavar=Metavar.list,
        type=list_type(',', int),
        help=
        "R|Threshold image using Adaptive algorithm (from skimage). Provide 2 values separated by ',' that "
        "correspond to the parameters below. For example, '-adap 7,0' corresponds to a block size of 7 and an "
        "offset of 0.\n"
        "  - Block size: Odd size of pixel neighborhood which is used to calculate the threshold value. \n"
        "  - Offset: Constant subtracted from weighted mean of neighborhood to calculate the local threshold "
        "value. Suggested offset is 0.",
        required=False)
    thresholding.add_argument(
        "-otsu-median",
        metavar=Metavar.list,
        type=list_type(',', int),
        help=
        "R|Threshold image using Median Otsu algorithm (from dipy). Provide 2 values separated by ',' that "
        "correspond to the parameters below. For example, '-otsu-median 3,5' corresponds to a filter size of 3 "
        "repeated over 5 iterations.\n"
        "  - Size: Radius (in voxels) of the applied median filter.\n"
        "  - Iterations: Number of passes of the median filter.",
        required=False)
    thresholding.add_argument(
        '-percent',
        type=int,
        help="Threshold image using percentile of its histogram.",
        metavar=Metavar.int,
        required=False)
    thresholding.add_argument(
        "-thr",
        type=float,
        help='Use following number to threshold image (zero below number).',
        metavar=Metavar.float,
        required=False)

    mathematical = parser.add_argument_group("MATHEMATICAL MORPHOLOGY")
    mathematical.add_argument(
        '-dilate',
        type=int,
        metavar=Metavar.int,
        help=
        "Dilate binary or greyscale image with specified size. If shape={'square', 'cube'}: size corresponds to the length of "
        "an edge (size=1 has no effect). If shape={'disk', 'ball'}: size corresponds to the radius, not including "
        "the center element (size=0 has no effect).",
        required=False)
    mathematical.add_argument(
        '-erode',
        type=int,
        metavar=Metavar.int,
        help=
        "Erode binary or greyscale image with specified size. If shape={'square', 'cube'}: size corresponds to the length of "
        "an edge (size=1 has no effect). If shape={'disk', 'ball'}: size corresponds to the radius, not including "
        "the center element (size=0 has no effect).",
        required=False)
    mathematical.add_argument(
        '-shape',
        help=
        "R|Shape of the structuring element for the mathematical morphology operation. Default: ball.\n"
        "If a 2D shape {'disk', 'square'} is selected, -dim must be specified.",
        required=False,
        choices=('square', 'cube', 'disk', 'ball'),
        default='ball')
    mathematical.add_argument(
        '-dim',
        type=int,
        help=
        "Dimension of the array which 2D structural element will be orthogonal to. For example, if you wish to "
        "apply a 2D disk kernel in the X-Y plane, leaving Z unaffected, parameters will be: shape=disk, dim=2.",
        required=False,
        choices=(0, 1, 2))

    filtering = parser.add_argument_group("FILTERING METHODS")
    filtering.add_argument(
        "-smooth",
        metavar=Metavar.list,
        type=list_type(',', float),
        help=
        'Gaussian smoothing filtering. Supply values for standard deviations in mm. If a single value is provided, '
        'it will be applied to each axis of the image. If multiple values are provided, there must be one value '
        'per image axis. (Examples: "-smooth 2.0,3.0,2.0" (3D image), "-smooth 2.0" (any-D image)).',
        required=False)
    filtering.add_argument(
        '-laplacian',
        metavar=Metavar.list,
        type=list_type(',', float),
        help=
        'Laplacian filtering. Supply values for standard deviations in mm. If a single value is provided, it will '
        'be applied to each axis of the image. If multiple values are provided, there must be one value per '
        'image axis. (Examples: "-laplacian 2.0,3.0,2.0" (3D image), "-laplacian 2.0" (any-D image)).',
        required=False)
    filtering.add_argument(
        '-denoise',
        help=
        'R|Non-local means adaptative denoising from P. Coupe et al. as implemented in dipy. Separate with ". Example: p=1,b=3\n'
        ' p: (patch radius) similar patches in the non-local means are searched for locally, inside a cube of side 2*p+1 centered at each voxel of interest. Default: p=1\n'
        ' b: (block radius) the size of the block to be used (2*b+1) in the blockwise non-local means implementation. Default: b=5 '
        '    Note, block radius must be smaller than the smaller image dimension: default value is lowered for small images)\n'
        'To use default parameters, write -denoise 1',
        required=False)

    similarity = parser.add_argument_group("SIMILARITY METRIC")
    similarity.add_argument(
        '-mi',
        metavar=Metavar.file,
        help=
        'Compute the mutual information (MI) between both input files (-i and -mi) as in: '
        'http://scikit-learn.org/stable/modules/generated/sklearn.metrics.mutual_info_score.html',
        required=False)
    similarity.add_argument(
        '-minorm',
        metavar=Metavar.file,
        help=
        'Compute the normalized mutual information (MI) between both input files (-i and -mi) as in: '
        'http://scikit-learn.org/stable/modules/generated/sklearn.metrics.normalized_mutual_info_score.html',
        required=False)
    similarity.add_argument(
        '-corr',
        metavar=Metavar.file,
        help=
        'Compute the cross correlation (CC) between both input files (-i and -cc).',
        required=False)

    misc = parser.add_argument_group("MISC")
    misc.add_argument('-symmetrize',
                      type=int,
                      help='Symmetrize data along the specified dimension.',
                      required=False,
                      choices=(0, 1, 2))
    misc.add_argument('-type',
                      required=False,
                      help='Output type.',
                      choices=('uint8', 'int16', 'int32', 'float32',
                               'complex64', 'float64', 'int8', 'uint16',
                               'uint32', 'int64', 'uint64'))
    optional.add_argument(
        '-v',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1, 2],
        default=1,
        # Values [0, 1, 2] map to logging levels [WARNING, INFO, DEBUG], but are also used as "if verbose == #" in API
        help=
        "Verbosity. 0: Display only errors/warnings, 1: Errors/warnings + info messages, 2: Debug mode"
    )

    return parser
Example #7
0
def get_parser():

    param_default = Param()

    parser = SCTArgumentParser(
        description=(
            f"This program extracts metrics (e.g., DTI or MTR) within labels. Labels could be a single file or "
            f"a folder generated with 'sct_warp_template' containing multiple label files and a label "
            f"description file (info_label.txt). The labels should be in the same space coordinates as the "
            f"input image.\n"
            f"\n"
            f"The labels used by default are taken from the PAM50 template. To learn about the available PAM50 "
            f"white/grey matter atlas labels and their corresponding ID values, please refer to: "
            f"https://spinalcordtoolbox.com/en/latest/overview/concepts/pam50.html#white-and-grey-matter-atlas-pam50-atlas\n"
            f"\n"
            f"To compute FA within labels 0, 2 and 3 within vertebral levels C2 to C7 using binary method:\n"
            f"sct_extract_metric -i dti_FA.nii.gz -l 0,2,3 -vert 2:7 -method bin\n"
            f"\n"
            f"To compute average MTR in a region defined by a single label file (could be binary or 0-1 "
            f"weighted mask) between slices 1 and 4:\n"
            f"sct_extract_metric -i mtr.nii.gz -f "
            f"my_mask.nii.gz -z 1:4 -method wa")
    )
    mandatory = parser.add_argument_group("\nMANDATORY ARGUMENTS")
    mandatory.add_argument(
        '-i',
        metavar=Metavar.file,
        required=True,
        help="Image file to extract metrics from. Example: FA.nii.gz"
    )

    optional = parser.add_argument_group("\nOPTIONAL ARGUMENTS")
    optional.add_argument(
        "-h",
        "--help",
        action="help",
        help="Show this help message and exit."
    )
    optional.add_argument(
        '-f',
        metavar=Metavar.folder,
        default=os.path.join("label", "atlas"),
        help=(f"Single label file, or folder that contains WM tract labels."
              f"Example: {os.path.join(__data_dir__, 'atlas')}")
    )
    optional.add_argument(
        '-l',
        metavar=Metavar.str,
        default='',
        help="Label IDs to extract the metric from. Default = all labels. Separate labels with ','. To select a group "
             "of consecutive labels use ':'. Example: 1:3 is equivalent to 1,2,3. Maximum Likelihood (or MAP) is "
             "computed using all tracts, but only values of the selected tracts are reported."
    )
    optional.add_argument(
        '-list-labels',
        action=_ListLabelsAction,
        nargs=0,
        help="List available labels. These labels are defined in the file 'info_label.txt' located in the folder "
             "specified by the flag '-f'."
    )
    optional.add_argument(
        '-method',
        choices=['ml', 'map', 'wa', 'bin', 'median', 'max'],
        default=param_default.method,
        help="Method to extract metrics.\n"
             "  - ml: maximum likelihood.\n"
             "    This method is recommended for large labels and low noise. Also, this method should only be used"
             " with the PAM50 white/gray matter atlas, or with any custom atlas as long as the sum across all labels"
             " equals 1, in each voxel part of the atlas.\n"
             "  - map: maximum a posteriori.\n"
             "    Mean priors are estimated by maximum likelihood within three clusters"
             " (white matter, gray matter and CSF). Tract and noise variance are set with flag -p."
             " This method should only be used with the PAM50 white/gray matter atlas, or with any custom atlas"
             " as long as the sum across all labels equals 1, in each voxel part of the atlas.\n"
             "  - wa: weighted average\n"
             "  - bin: binarize mask (threshold=0.5)\n"
             "  - median: weighted median.\n"
             "    This implementation of the median treats quantiles as a continuous (vs. discrete) function. For"
             " more details, see https://pypi.org/project/wquantiles/.\n"
             "  - max: for each z-slice of the input data, extract the max value for each slice of the input data."
    )
    optional.add_argument(
        '-append',
        type=int,
        choices=(0, 1),
        default=0,
        help="Whether to append results as a new line in the output csv file instead of overwriting it. 0 = no, 1 = yes"
    )
    optional.add_argument(
        '-combine',
        type=int,
        choices=(0, 1),
        default=0,
        help="Whether to combine multiple labels into a single estimation. 0 = no, 1 = yes"
    )
    optional.add_argument(
        '-o',
        metavar=Metavar.file,
        default=param_default.fname_output,
        help="File name of the output result file collecting the metric estimation results. Include the '.csv' "
             "file extension in the file name. Example: extract_metric.csv"
    )
    optional.add_argument(
        '-output-map',
        metavar=Metavar.file,
        default='',
        help="File name for an image consisting of the atlas labels multiplied by the estimated metric values "
             "yielding the metric value map, useful to assess the metric estimation and especially partial volume "
             "effects."
    )
    optional.add_argument(
        '-z',
        metavar=Metavar.str,
        default=param_default.slices_of_interest,
        help="Slice range to estimate the metric from. First slice is 0. Example: 5:23\n"
             "You can also select specific slices using commas. Example: 0,2,3,5,12'"
    )
    optional.add_argument(
        '-perslice',
        type=int,
        choices=(0, 1),
        default=param_default.perslice,
        help="Whether to output one metric per slice instead of a single output metric. 0 = no, 1 = yes.\n"
             "Please note that when methods ml or map are used, outputting a single metric per slice and then "
             "averaging them all is not the same as outputting a single metric at once across all slices."
    )
    optional.add_argument(
        '-vert',
        metavar=Metavar.str,
        default=param_default.vertebral_levels,
        help="Vertebral levels to estimate the metric across. Example: 2:9 (for C2 to T2)"
    )
    optional.add_argument(
        '-vertfile',
        metavar=Metavar.file,
        default=os.path.join(".", "label", "template", "PAM50_levels.nii.gz"),
        help="Vertebral labeling file. Only use with flag -vert.\n"
             "The input Image and the vertebral labelling file must in the same voxel coordinate system "
             "and must match the dimensions between each other."
    )
    optional.add_argument(
        '-perlevel',
        type=int,
        metavar=Metavar.int,
        default=0,
        help="Whether to output one metric per vertebral level instead of a single output metric. 0 = no, 1 = yes.\n"
             "Please note that this flag needs to be used with the -vert option."
    )
    optional.add_argument(
        '-v',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1, 2],
        default=1,
        # Values [0, 1, 2] map to logging levels [WARNING, INFO, DEBUG], but are also used as "if verbose == #" in API
        help="Verbosity. 0: Display only errors/warnings, 1: Errors/warnings + info messages, 2: Debug mode"
    )

    advanced = parser.add_argument_group("\nFOR ADVANCED USERS")
    advanced.add_argument(
        '-param',
        metavar=Metavar.str,
        default='',
        help="Advanced parameters for the 'map' method. Separate with comma. All items must be listed (separated "
             "with comma).\n"
             "  - #1: standard deviation of metrics across labels\n"
             "  - #2: standard deviation of the noise (assumed Gaussian)"
    )
    advanced.add_argument(
        '-fix-label',
        metavar=Metavar.list,
        type=list_type(',', str),
        default='',
        help="When using ML or MAP estimations, if you do not want to estimate the metric in one label and fix its "
             "value to avoid effects on other labels, specify <label_ID>,<metric_value. Example: -fix-label 36,0 "
             "(Fix the CSF value)"
    )
    advanced.add_argument(
        '-norm-file',
        metavar=Metavar.file,
        default='',
        help='Filename of the label by which the user wants to normalize.'
    )
    advanced.add_argument(
        '-norm-method',
        choices=['sbs', 'whole'],
        default='',
        help="Method to use for normalization:\n"
             "  - sbs: normalization slice-by-slice\n"
             "  - whole: normalization by the metric value in the whole label for all slices."
    )
    advanced.add_argument(
        '-mask-weighted',
        metavar=Metavar.file,
        default='',
        help="Nifti mask to weight each voxel during ML or MAP estimation. Example: PAM50_wm.nii.gz"
    )
    advanced.add_argument(
        '-discard-neg-val',
        choices=('0', '1'),
        default='0',
        help='Whether to discard voxels with negative value when computing metrics statistics. 0 = no, 1 = yes'
    )

    return parser
def get_parser():
    # Initialize the parser
    parser = SCTArgumentParser(
        description="This program co-registers two 3D volumes. The deformation is non-rigid and is constrained along "
                    "Z direction (i.e., axial plane). Hence, this function assumes that orientation of the destination "
                    "image is axial (RPI). If you need to register two volumes with large deformations and/or "
                    "different contrasts, it is recommended to input spinal cord segmentations (binary mask) in order "
                    "to achieve maximum robustness. The program outputs a warping field that can be used to register "
                    "other images to the destination image. To apply the warping field to another image, use "
                    "'sct_apply_transfo'\n"
                    "\n"
                    "Tips:\n"
                    " - For a registration step using segmentations, use the MeanSquares metric. Also, simple "
                    "algorithm will be very efficient, for example centermass as a 'preregistration'.\n"
                    " - For a registration step using images of different contrast, use the Mutual Information (MI) "
                    "metric.\n"
                    " - Combine the steps by increasing the complexity of the transformation performed in each step, "
                    "for example: -param step=1,type=seg,algo=slicereg,metric=MeanSquares:"
                    "step=2,type=seg,algo=affine,metric=MeanSquares,gradStep=0.2:"
                    "step=3,type=im,algo=syn,metric=MI,iter=5,shrink=2\n"
                    " - When image contrast is low, a good option is to perform registration only based on the image "
                    "segmentation, i.e. using type=seg\n"
                    " - Columnwise algorithm needs to be applied after a translation and rotation such as centermassrot "
                    "algorithm. For example: -param step=1,type=seg,algo=centermassrot,metric=MeanSquares:"
                    "step=2,type=seg,algo=columnwise,metric=MeanSquares"
    )

    mandatory = parser.add_argument_group("\nMANDATORY ARGUMENTS")
    mandatory.add_argument(
        '-i',
        metavar=Metavar.file,
        required=True,
        help="Image source. Example: src.nii.gz"
    )
    mandatory.add_argument(
        '-d',
        metavar=Metavar.file,
        required=True,
        help="Image destination. Example: dest.nii.gz"
    )

    optional = parser.add_argument_group("\nOPTIONAL ARGUMENTS")
    optional.add_argument(
        "-h",
        "--help",
        action="help",
        help="Show this help message and exit."
    )
    optional.add_argument(
        '-iseg',
        metavar=Metavar.file,
        help="Segmentation source. Example: src_seg.nii.gz"
    )
    optional.add_argument(
        '-dseg',
        metavar=Metavar.file,
        help="Segmentation destination. Example: dest_seg.nii.gz"
    )
    optional.add_argument(
        '-ilabel',
        metavar=Metavar.file,
        help="Labels source."
    )
    optional.add_argument(
        '-dlabel',
        metavar=Metavar.file,
        help="Labels destination."
    )
    optional.add_argument(
        '-initwarp',
        metavar=Metavar.file,
        help="Initial warping field to apply to the source image."
    )
    optional.add_argument(
        '-initwarpinv',
        metavar=Metavar.file,
        help="Initial inverse warping field to apply to the destination image (only use if you wish to generate the "
             "dest->src warping field)"
    )
    optional.add_argument(
        '-m',
        metavar=Metavar.file,
        help="Mask that can be created with sct_create_mask to improve accuracy over region of interest. This mask "
             "will be used on the destination image. Example: mask.nii.gz"
    )
    optional.add_argument(
        '-o',
        metavar=Metavar.file,
        help="Name of output file. Example: src_reg.nii.gz"
    )
    optional.add_argument(
        '-owarp',
        metavar=Metavar.file,
        help="Name of output forward warping field."
    )
    optional.add_argument(
        '-owarpinv',
        metavar=Metavar.file,
        help="Name of output inverse warping field."
    )
    optional.add_argument(
        '-param',
        metavar=Metavar.list,
        type=list_type(':', str),
        help=(f"Parameters for registration. Separate arguments with \",\". Separate steps with \":\".\n"
              f"Example: step=1,type=seg,algo=slicereg,metric=MeanSquares:step=2,type=im,algo=syn,metric=MI,iter=5,"
              f"shrink=2\n"
              f"  - step: <int> Step number (starts at 1, except for type=label).\n"
              f"  - type: {{im, seg, imseg, label}} type of data used for registration. Use type=label only at "
              f"step=0.\n"
              f"  - algo: The algorithm used to compute the transformation. Default={DEFAULT_PARAMREGMULTI.steps['1'].algo}\n"
              f"    * translation: translation in X-Y plane (2dof)\n"
              f"    * rigid: translation + rotation in X-Y plane (4dof)\n"
              f"    * affine: translation + rotation + scaling in X-Y plane (6dof)\n"
              f"    * syn: non-linear symmetric normalization\n"
              f"    * bsplinesyn: syn regularized with b-splines\n"
              f"    * slicereg: regularized translations (see: goo.gl/Sj3ZeU)\n"
              f"    * centermass: slicewise center of mass alignment (seg only).\n"
              f"    * centermassrot: slicewise center of mass and rotation alignment using method specified in "
              f"'rot_method'\n"
              f"    * columnwise: R-L scaling followed by A-P columnwise alignment (seg only).\n"
              f"  - slicewise: <int> Slice-by-slice 2d transformation. "
              f"Default={DEFAULT_PARAMREGMULTI.steps['1'].slicewise}.\n"
              f"  - metric: {{CC, MI, MeanSquares}}. Default={DEFAULT_PARAMREGMULTI.steps['1'].metric}.\n"
              f"    * CC: The cross correlation metric compares the images based on their intensities but with a small "
              f"normalization. It can be used with images with the same contrast (for ex. T2-w with T2-w). In this "
              f"case it is very efficient but the computation time can be very long.\n"
              f"    * MI: the mutual information metric compares the images based on their entropy, therefore the "
              f"images need to be big enough to have enough information. It works well for images with different "
              f"contrasts (for example T2-w with T1-w) but not on segmentations.\n"
              f"    * MeanSquares: The mean squares metric compares the images based on their intensities. It can be "
              f"used only with images that have exactly the same contrast (with the same intensity range) or with "
              f"segmentations.\n"
              f"  - iter: <int> Number of iterations. Default={DEFAULT_PARAMREGMULTI.steps['1'].iter}.\n"
              f"  - shrink: <int> Shrink factor. A shrink factor of 2 will down sample the images by a factor of 2 to "
              f"do the registration, and thus allow bigger deformations (and be faster to compute). It is usually "
              f"combined with a smoothing. (only for syn/bsplinesyn). Default={DEFAULT_PARAMREGMULTI.steps['1'].shrink}.\n"
              f"  - smooth: <int> Smooth factor (in mm). Note: if algo={{centermassrot,columnwise}} the smoothing "
              f"kernel is: SxSx0. Otherwise it is SxSxS. Default={DEFAULT_PARAMREGMULTI.steps['1'].smooth}.\n"
              f"  - laplacian: <int> Laplace filter using Gaussian second derivatives, applied before registration. "
              f"The input number correspond to the standard deviation of the Gaussian filter. "
              f"Default={DEFAULT_PARAMREGMULTI.steps['1'].laplacian}.\n"
              f"  - gradStep: <float> The gradient step used by the function opitmizer. A small gradient step can lead "
              f"to a more accurate registration but will take longer to compute, with the risk to not reach "
              f"convergence. A bigger gradient step will make the registration faster but the result can be far from "
              f"an optimum. Default={DEFAULT_PARAMREGMULTI.steps['1'].gradStep}.\n"
              f"  - deformation: ?x?x?: Restrict deformation (for ANTs algo). Replace ? by 0 (no deformation) or 1 "
              f"(deformation). Default={DEFAULT_PARAMREGMULTI.steps['1'].deformation}.\n"
              f"  - init: Initial translation alignment based on:\n"
              f"    * geometric: Geometric center of images\n"
              f"    * centermass: Center of mass of images\n"
              f"    * origin: Physical origin of images\n"
              f"  - poly: <int> Polynomial degree of regularization (only for algo=slicereg). "
              f"Default={DEFAULT_PARAMREGMULTI.steps['1'].poly}.\n"
              f"  - filter_size: <float> Filter size for regularization (only for algo=centermassrot). "
              f"Default={DEFAULT_PARAMREGMULTI.steps['1'].filter_size}.\n"
              f"  - smoothWarpXY: <int> Smooth XY warping field (only for algo=columnwize). "
              f"Default={DEFAULT_PARAMREGMULTI.steps['1'].smoothWarpXY}.\n"
              f"  - pca_eigenratio_th: <int> Min ratio between the two eigenvalues for PCA-based angular adjustment "
              f"(only for algo=centermassrot and rot_method=pca). "
              f"Default={DEFAULT_PARAMREGMULTI.steps['1'].pca_eigenratio_th}.\n"
              f"  - dof: <str> Degree of freedom for type=label. Separate with '_'. T stands for translation and R "
              f"stands for rotation, x, y, and z indicating the direction. For example, Tx_Ty_Tz_Rx_Ry_Rz would allow "
              f"translation on x, y and z axes and rotation on x, y and z axes. "
              f"Default={DEFAULT_PARAMREGMULTI.steps['0'].dof}.\n"
              f"  - rot_method {{pca, hog, pcahog}}: rotation method to be used with algo=centermassrot. If using hog "
              f"or pcahog, type should be set to imseg. Default={DEFAULT_PARAMREGMULTI.steps['1'].rot_method}\n"
              f"    * pca: approximate cord segmentation by an ellipse and finds it orientation using PCA's "
              f"eigenvectors\n"
              f"    * hog: finds the orientation using the symmetry of the image\n"
              f"    * pcahog: tries method pca and if it fails, uses method hog.\n")
    )
    optional.add_argument(
        '-identity',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1],
        default=0,
        help="Supplying this option will skip registration optimization (e.g. translations, rotations, deformations) "
             "and will only rely on the qform (from the NIfTI header) of the source and destination images. Use this "
             "option if you wish to put the source image into the space of the destination image (i.e. match "
             "dimension, resolution and orientation)."
    )
    optional.add_argument(
        '-z',
        metavar=Metavar.int,
        type=int,
        default=Param().padding,
        help="Size of z-padding to enable deformation at edges when using SyN."
    )
    optional.add_argument(
        '-x',
        choices=['nn', 'linear', 'spline'],
        default='linear',
        help="Final interpolation."
    )
    optional.add_argument(
        '-ofolder',
        metavar=Metavar.folder,
        action=ActionCreateFolder,
        help="Output folder. Example: reg_results"
    )
    optional.add_argument(
        '-qc',
        metavar=Metavar.folder,
        action=ActionCreateFolder,
        help="The path where the quality control generated content will be saved."
    )
    optional.add_argument(
        '-qc-dataset',
        metavar=Metavar.str,
        help="If provided, this string will be mentioned in the QC report as the dataset the process was run on."
    )
    optional.add_argument(
        '-qc-subject',
        metavar=Metavar.str,
        help="If provided, this string will be mentioned in the QC report as the subject the process was run on."
    )
    optional.add_argument(
        '-r',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1],
        default=1,
        help="Whether to remove temporary files. 0 = no, 1 = yes"
    )
    optional.add_argument(
        '-v',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1, 2],
        default=1,
        # Values [0, 1, 2] map to logging levels [WARNING, INFO, DEBUG], but are also used as "if verbose == #" in API
        help="Verbosity. 0: Display only errors/warnings, 1: Errors/warnings + info messages, 2: Debug mode"
    )
    return parser
Example #9
0
def get_parser():

    # initialize parameters
    param_default = ParamMoco(is_diffusion=True, group_size=3, metric='MI', smooth='1')

    parser = SCTArgumentParser(
        description="Motion correction of dMRI data. Some of the features to improve robustness were proposed in Xu et "
                    "al. (http://dx.doi.org/10.1016/j.neuroimage.2012.11.014) and include:\n"
                    "  - group-wise (-g)\n"
                    "  - slice-wise regularized along z using polynomial function (-param). For more info about the "
                    "method, type: isct_antsSliceRegularizedRegistration\n"
                    "  - masking (-m)\n"
                    "  - iterative averaging of target volume\n"
    )

    mandatory = parser.add_argument_group("\nMANDATORY ARGUMENTS")
    mandatory.add_argument(
        '-i',
        metavar=Metavar.file,
        required=True,
        help="Diffusion data. Example: dmri.nii.gz"
    )
    mandatory.add_argument(
        '-bvec',
        metavar=Metavar.file,
        required=True,
        help='Bvecs file. Example: bvecs.txt'
    )

    optional = parser.add_argument_group("\nOPTIONAL ARGUMENTS")
    optional.add_argument(
        "-h",
        "--help",
        action="help",
        help="Show this help message and exit."
    )
    optional.add_argument(
        '-bval',
        metavar=Metavar.file,
        default=param_default.fname_bvals,
        help='Bvals file. Example: bvals.txt',
    )
    optional.add_argument(
        '-bvalmin',
        type=float,
        metavar=Metavar.float,
        default=param_default.bval_min,
        help='B-value threshold (in s/mm2) below which data is considered as b=0. Example: 50.0',
    )
    optional.add_argument(
        '-g',
        type=int,
        metavar=Metavar.int,
        default=param_default.group_size,
        help='Group nvols successive dMRI volumes for more robustness. Example: 2',
    )
    optional.add_argument(
        '-m',
        metavar=Metavar.file,
        default=param_default.fname_mask,
        help='Binary mask to limit voxels considered by the registration metric. Example: dmri_mask.nii.gz',
    )
    optional.add_argument(
        '-param',
        metavar=Metavar.list,
        type=list_type(',', str),
        help=f"Advanced parameters. Assign value with \"=\", and separate arguments with \",\".\n"
             f"  - poly [int]: Degree of polynomial function used for regularization along Z. For no regularization "
             f"set to 0. Default={param_default.poly}.\n"
             f"  - smooth [mm]: Smoothing kernel. Default={param_default.smooth}.\n"
             f"  - metric {{MI, MeanSquares, CC}}: Metric used for registration. Default={param_default.metric}.\n"
             f"  - gradStep [float]: Searching step used by registration algorithm. The higher the more deformation "
             f"allowed. Default={param_default.gradStep}.\n"
             f"  - sample [None or 0-1]: Sampling rate used for registration metric. "
             f"Default={param_default.sampling}.\n"
    )
    optional.add_argument(
        '-x',
        choices=['nn', 'linear', 'spline'],
        default=param_default.interp,
        help="Final interpolation."
    )
    optional.add_argument(
        '-ofolder',
        metavar=Metavar.folder,
        action=ActionCreateFolder,
        default=param_default.path_out,
        help="Output folder. Example: dmri_moco_results"
    )
    optional.add_argument(
        "-r",
        choices=('0', '1'),
        default=param_default.remove_temp_files,
        help="Remove temporary files. 0 = no, 1 = yes"
    )
    optional.add_argument(
        '-v',
        metavar=Metavar.int,
        type=int,
        choices=[0, 1, 2],
        default=1,
        # Values [0, 1, 2] map to logging levels [WARNING, INFO, DEBUG], but are also used as "if verbose == #" in API
        help="Verbosity. 0: Display only errors/warnings, 1: Errors/warnings + info messages, 2: Debug mode"
    )
    optional.add_argument(
        '-qc',
        metavar=Metavar.folder,
        action=ActionCreateFolder,
        help="The path where the quality control generated content will be saved. (Note: "
             "Both '-qc' and '-qc-seg' are required in order to generate a QC report.)"
    )
    optional.add_argument(
        '-qc-seg',
        metavar=Metavar.file,
        help="Segmentation of spinal cord to improve cropping in qc report. (Note: "
             "Both '-qc' and '-qc-seg' are required in order to generate a QC report.)"
    )
    optional.add_argument(
        '-qc-fps',
        metavar=Metavar.float,
        type=float,
        default=3,
        help="This float number is the number of frames per second for the output gif images."
    )
    optional.add_argument(
        '-qc-dataset',
        metavar=Metavar.str,
        help="If provided, this string will be mentioned in the QC report as the dataset the process was run on."
    )
    optional.add_argument(
        '-qc-subject',
        metavar=Metavar.str,
        help="If provided, this string will be mentioned in the QC report as the subject the process was run on."
    )

    return parser