# This file was auto generated by Styx.
# Do not edit this file directly.

import typing
import pathlib
from styxdefs import *
import dataclasses

ANTS_MOTION_CORR_METADATA = Metadata(
    id="101179d7b402b3245503ed337e9b9c5479b1f966.boutiques",
    name="antsMotionCorr",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


class AntsMotionCorrOutputs(typing.NamedTuple):
    """
    Output object returned when calling `ants_motion_corr(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_transform_prefix: OutputPathType
    """The output is the transformation matrix."""
    warped_image: OutputPathType
    """The output is the warped moving image."""
    average_image_output: OutputPathType
    """The output is the averaged image of the input time series."""


def ants_motion_corr(
    dimensionality: typing.Literal[2, 3] | None = None,
    n_images: int | None = None,
    metric: str | None = None,
    use_fixed_reference_image: typing.Literal[0, 1] | None = None,
    use_scales_estimator: bool = False,
    transform: str | None = None,
    iterations: str | None = None,
    smoothing_sigmas: str | None = None,
    shrink_factors: str | None = None,
    output: str | None = None,
    average_image: bool = False,
    write_displacement: bool = False,
    use_histogram_matching: typing.Literal[0, 1] | None = None,
    random_seed: int | None = None,
    interpolation: typing.Literal["Linear", "NearestNeighbor", "BSpline", "BlackmanWindowedSinc", "CosineWindowedSinc", "WelchWindowedSinc", "HammingWindowedSinc", "LanczosWindowedSinc"] | None = None,
    verbose: typing.Literal[0, 1] | None = None,
    runner: Runner | None = None,
) -> AntsMotionCorrOutputs:
    """
    ANTS Motion Correction application to perform motion correction on 4D time
    series data.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, the program tries to\
            infer the dimensionality from the input image.
        n_images: This option sets the number of images to use to construct the\
            template image.
        metric: Metrics for registration: GC (global correlation), CC (ANTS\
            neighborhood cross correlation), MI (Mutual information), and Demons.
        use_fixed_reference_image: Use a fixed reference image to correct all\
            volumes, instead of correcting each image to the prior volume in the\
            time series.
        use_scales_estimator: Use the scale estimator to control optimization.
        transform: Several transform options are available: Affine, Rigid,\
            GaussianDisplacementField, SyN.
        iterations: Specify the number of iterations at each level.
        smoothing_sigmas: Specify the sigma for smoothing at each level.\
            Smoothing may be specified in mm units or voxels with 'AxBxCmm' or\
            'AxBxCvox'. No units implies voxels.
        shrink_factors: Specify the shrink factor for the virtual domain\
            (typically the fixed image) at each level.
        output: Specify the output transform prefix (output format is .nii.gz\
            ). Optionally, one can choose to warp the moving image to the fixed\
            space and, if the inverse transform exists, one can also output the\
            warped fixed image.
        average_image: Average the input time series image.
        write_displacement: Write the low-dimensional 3D transforms to a 4D\
            displacement field.
        use_histogram_matching: Histogram match the moving images to the\
            reference image.
        random_seed: Use a fixed seed for random number generation.
        interpolation: Several interpolation options are available in ITK. The\
            above are available (default Linear).
        verbose: Verbose output.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsMotionCorrOutputs`).
    """
    if random_seed is not None and not (1 <= random_seed): 
        raise ValueError(f"'random_seed' must be greater than 1 <= x but was {random_seed}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTS_MOTION_CORR_METADATA)
    cargs = []
    cargs.append("antsMotionCorr")
    if dimensionality is not None:
        cargs.extend([
            "--dimensionality",
            str(dimensionality)
        ])
    if n_images is not None:
        cargs.extend([
            "--n-images",
            str(n_images)
        ])
    if metric is not None:
        cargs.extend([
            "--metric",
            metric
        ])
    if use_fixed_reference_image is not None:
        cargs.extend([
            "--useFixedReferenceImage",
            str(use_fixed_reference_image)
        ])
    if use_scales_estimator:
        cargs.append("--useScalesEstimator")
    if transform is not None:
        cargs.extend([
            "--transform",
            transform
        ])
    if iterations is not None:
        cargs.extend([
            "--iterations",
            iterations
        ])
    if smoothing_sigmas is not None:
        cargs.extend([
            "--smoothingSigmas",
            smoothing_sigmas
        ])
    if shrink_factors is not None:
        cargs.extend([
            "--shrinkFactors",
            shrink_factors
        ])
    if output is not None:
        cargs.extend([
            "--output",
            output
        ])
    if average_image:
        cargs.append("--average-image")
    if write_displacement:
        cargs.append("--write-displacement")
    if use_histogram_matching is not None:
        cargs.extend([
            "--use-histogram-matching",
            str(use_histogram_matching)
        ])
    if random_seed is not None:
        cargs.extend([
            "--random-seed",
            str(random_seed)
        ])
    if interpolation is not None:
        cargs.extend([
            "--interpolation",
            interpolation
        ])
    if verbose is not None:
        cargs.extend([
            "--verbose",
            str(verbose)
        ])
    ret = AntsMotionCorrOutputs(
        root=execution.output_file("."),
        output_transform_prefix=execution.output_file("[OUTPUT_TRANSFORM_PREFIX]Affine.mat"),
        warped_image=execution.output_file("[OUTPUT_TRANSFORM_PREFIX]Warped.nii.gz"),
        average_image_output=execution.output_file("[OUTPUT_TRANSFORM_PREFIX]Average.nii.gz"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "ANTS_MOTION_CORR_METADATA",
    "AntsMotionCorrOutputs",
    "ants_motion_corr",
]
