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

import typing
import pathlib
from styxdefs import *
import dataclasses

INVWARP_METADATA = Metadata(
    id="778bad288efe828813a147cbd6f4c4be14fad8ca.boutiques",
    name="invwarp",
    package="fsl",
    container_image_tag="mcin/fsl:6.0.5",
)


class InvwarpOutputs(typing.NamedTuple):
    """
    Output object returned when calling `invwarp(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_volume: OutputPathType
    """Output inverse warped volume"""


def invwarp(
    warpvol: InputPathType,
    outvol: str,
    refvol: InputPathType,
    relflag: bool = False,
    absflag: bool = False,
    noconstraintflag: bool = False,
    jmin: float | None = 0.01,
    jmax: float | None = 100.0,
    debugflag: bool = False,
    verboseflag: bool = False,
    runner: Runner | None = None,
) -> InvwarpOutputs:
    """
    Inverse warp tool from FSL suite.
    
    Author: University of Oxford (Jesper Andersson)
    
    URL: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FNIRT
    
    Args:
        warpvol: Filename for warp/shiftmap transform (volume).
        outvol: Filename for output (inverse warped) image.
        refvol: Filename for new reference image, i.e., what was originally the\
            input image (determines inverse warpvol's FOV and pixdims).
        relflag: Use relative warp convention: x' = x + w(x).
        absflag: Use absolute warp convention (default): x' = w(x).
        noconstraintflag: Do not apply the Jacobian constraint.
        jmin: Minimum acceptable Jacobian value for constraint (default 0.01).
        jmax: Maximum acceptable Jacobian value for constraint (default 100.0).
        debugflag: Turn on debugging output.
        verboseflag: Switch on diagnostic messages.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `InvwarpOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(INVWARP_METADATA)
    cargs = []
    cargs.append("invwarp")
    cargs.append("-w")
    cargs.extend([
        "-w",
        execution.input_file(warpvol)
    ])
    cargs.append("-o")
    cargs.extend([
        "-o",
        outvol
    ])
    cargs.append("-r")
    cargs.extend([
        "-r",
        execution.input_file(refvol)
    ])
    if relflag:
        cargs.append("--rel")
    if absflag:
        cargs.append("--abs")
    if noconstraintflag:
        cargs.append("--noconstraint")
    if jmin is not None:
        cargs.extend([
            "--jmin",
            str(jmin)
        ])
    if jmax is not None:
        cargs.extend([
            "--jmax",
            str(jmax)
        ])
    if debugflag:
        cargs.append("--debug")
    if verboseflag:
        cargs.append("-v")
    ret = InvwarpOutputs(
        root=execution.output_file("."),
        out_volume=execution.output_file(outvol),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "INVWARP_METADATA",
    "InvwarpOutputs",
    "invwarp",
]
