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

import typing
import pathlib
from styxdefs import *
import dataclasses

APPLYTOPUP_METADATA = Metadata(
    id="796c87a5699f7d6e7a6f4c3d38e953899925bbd6.boutiques",
    name="applytopup",
    package="fsl",
    container_image_tag="mcin/fsl:6.0.5",
)


class ApplytopupOutputs(typing.NamedTuple):
    """
    Output object returned when calling `applytopup(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType
    """The output warped image."""


def applytopup(
    imain: list[InputPathType],
    datain: InputPathType,
    inindex: list[str],
    topup_: InputPathType,
    out: str,
    method: typing.Literal["jac", "lsr"] | None = None,
    interp: typing.Literal["trilinear", "spline"] | None = None,
    datatype: typing.Literal["char", "short", "int", "float", "double"] | None = None,
    verbose: bool = False,
    runner: Runner | None = None,
) -> ApplytopupOutputs:
    """
    applytopup applies corrections to images using the field estimates produced by
    topup.
    
    Author: University of Oxford (Jesper Andersson)
    
    Args:
        imain: Comma separated list of names of input image (to be corrected).
        datain: Name of text file with PE directions/times.
        inindex: Comma separated list of indices into --datain of the input\
            image (to be corrected).
        topup_: Name of field/movements (from topup).
        out: Basename for output (warped) image.
        method: Use jacobian modulation (jac) or least-squares resampling\
            (lsr), default=lsr.
        interp: Interpolation method {trilinear, spline}, default=spline.
        datatype: Force output data type [char short int float double].
        verbose: Switch on diagnostic messages.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ApplytopupOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(APPLYTOPUP_METADATA)
    cargs = []
    cargs.append("applytopup")
    cargs.append("--imain=" + ",".join([execution.input_file(f) for f in imain]))
    cargs.append("--datain=" + execution.input_file(datain))
    cargs.append("--inindex=" + ",".join(inindex))
    cargs.append("--topup=" + execution.input_file(topup_, resolve_parent=True))
    cargs.append("--out=" + out)
    if method is not None:
        cargs.append("--method=" + method)
    if interp is not None:
        cargs.append("--interp=" + interp)
    if datatype is not None:
        cargs.append("--datatype=" + datatype)
    if verbose:
        cargs.append("--verbose")
    ret = ApplytopupOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file(out),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "APPLYTOPUP_METADATA",
    "ApplytopupOutputs",
    "applytopup",
]
