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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_ROBUST_TEMPLATE_METADATA = Metadata(
    id="092f887514149896ea845584b32f67146d67d774.boutiques",
    name="mri_robust_template",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriRobustTemplateOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_robust_template(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_template: OutputPathType
    """Output template volume (final mean/median image)."""
    output_lta_transform: OutputPathType
    """Output transform file."""
    output_mapped_image: OutputPathType
    """Output mapped and resampled image."""
    output_weights_map: OutputPathType
    """Output weights map (outliers)."""


def mri_robust_template(
    mov_files: list[InputPathType],
    template_file: str,
    lta_files: list[str] | None = None,
    mapmov_files: list[str] | None = None,
    mapmovhdr_files: list[str] | None = None,
    weights_files: list[str] | None = None,
    runner: Runner | None = None,
) -> MriRobustTemplateOutputs:
    """
    Constructs an unbiased robust template for longitudinal volumes using an
    iterative method.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        mov_files: Input movable volumes to be aligned to common mean/median\
            template.
        template_file: Output template volume (final mean/median image).
        lta_files: Output transforms to template (for each input).
        mapmov_files: Output images: map and resample each input to template.
        mapmovhdr_files: Output images: header-adjusted movables (no\
            resampling).
        weights_files: Output weights (outliers) in target space.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriRobustTemplateOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_ROBUST_TEMPLATE_METADATA)
    cargs = []
    cargs.append("mri_robust_template")
    cargs.append("--mov")
    cargs.extend([execution.input_file(f) for f in mov_files])
    cargs.append("--template")
    cargs.append(template_file)
    cargs.append("[SENSITIVITY_OPTION]")
    if lta_files is not None:
        cargs.extend([
            "--lta",
            *lta_files
        ])
    if mapmov_files is not None:
        cargs.extend([
            "--mapmov",
            *mapmov_files
        ])
    if mapmovhdr_files is not None:
        cargs.extend([
            "--mapmovhdr",
            *mapmovhdr_files
        ])
    if weights_files is not None:
        cargs.extend([
            "--weights",
            *weights_files
        ])
    cargs.append("[OPTIONS]")
    ret = MriRobustTemplateOutputs(
        root=execution.output_file("."),
        output_template=execution.output_file(template_file),
        output_lta_transform=execution.output_file("[TMP_NAME].lta"),
        output_mapped_image=execution.output_file("[TMP_NAME]_to_template.mgz"),
        output_weights_map=execution.output_file("[TMP_NAME]_weights.mgz"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_ROBUST_TEMPLATE_METADATA",
    "MriRobustTemplateOutputs",
    "mri_robust_template",
]
