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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_AVERAGE_METADATA = Metadata(
    id="9f634edc8e7e1a23500b288fecc20c4dd605a410.boutiques",
    name="mri_average",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriAverageOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_average(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType
    """The averaged output volume."""


def mri_average(
    input_volumes: list[InputPathType],
    output_volume: str,
    rigid_alignment: bool = False,
    read_from_file: bool = False,
    dt: float | None = None,
    tol: float | None = None,
    conform: bool = False,
    noconform: bool = False,
    reduce: float | None = None,
    sinc_interpolation: float | None = None,
    trilinear: bool = False,
    window: bool = False,
    snapshots: float | None = None,
    translation: list[float] | None = None,
    rotation: list[float] | None = None,
    momentum: float | None = None,
    rms_alt: bool = False,
    percent: bool = False,
    binarize: float | None = None,
    absolute: bool = False,
    runner: Runner | None = None,
) -> MriAverageOutputs:
    """
    Averages multiple volumes with various options for alignment, interpolation, and
    transformations.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_volumes: Input volumes to average.
        output_volume: Output volume file.
        rigid_alignment: Rigid alignment of input volumes before averaging.
        read_from_file: Read volumes from an input file (first argument is the\
            input filename).
        dt: Set dt to n (default=1e-6).
        tol: Set tolerance to n (default=1e-5).
        conform: Interpolate volume to be isotropic 1mm^3 (on by default).
        noconform: Inhibit isotropic volume interpolation.
        reduce: Reduce input images n (default=2) times.
        sinc_interpolation: Using sinc interpolation with window width of 2*n\
            (default=3).
        trilinear: Use trilinear interpolation.
        window: Apply hanning window to volumes.
        snapshots: Write snapshots every n iterations.
        translation: Translation of second volume.
        rotation: Rotation of second volume around each axis in degrees.
        momentum: Use momentum n (default=0).
        rms_alt: Compute sqrt of average of sum of squares (RMS, same as -sqr).
        percent: Compute percentage.
        binarize: Binarize the input volumes using threshold th.
        absolute: Take absolute value of volume.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriAverageOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_AVERAGE_METADATA)
    cargs = []
    cargs.append("mri_average")
    cargs.extend([execution.input_file(f) for f in input_volumes])
    cargs.append(output_volume)
    if rigid_alignment:
        cargs.append("-a")
    if read_from_file:
        cargs.append("-F")
    if dt is not None:
        cargs.extend([
            "-dt",
            str(dt)
        ])
    if tol is not None:
        cargs.extend([
            "-tol",
            str(tol)
        ])
    if conform:
        cargs.append("-conform")
    if noconform:
        cargs.append("-noconform")
    if reduce is not None:
        cargs.extend([
            "-reduce",
            str(reduce)
        ])
    if sinc_interpolation is not None:
        cargs.extend([
            "-sinc",
            str(sinc_interpolation)
        ])
    if trilinear:
        cargs.append("-trilinear")
    if window:
        cargs.append("-window")
    if snapshots is not None:
        cargs.extend([
            "-w",
            str(snapshots)
        ])
    if translation is not None:
        cargs.extend([
            "-t",
            *map(str, translation)
        ])
    if rotation is not None:
        cargs.extend([
            "-r",
            *map(str, rotation)
        ])
    if momentum is not None:
        cargs.extend([
            "-m",
            str(momentum)
        ])
    if rms_alt:
        cargs.append("-rms")
    if percent:
        cargs.append("-p")
    if binarize is not None:
        cargs.extend([
            "-b",
            str(binarize)
        ])
    if absolute:
        cargs.append("-abs")
    ret = MriAverageOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file(output_volume),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_AVERAGE_METADATA",
    "MriAverageOutputs",
    "mri_average",
]
