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

import typing
import pathlib
from styxdefs import *
import dataclasses

NEW_INVWARP_METADATA = Metadata(
    id="99dbbd756c597bc63d56f925f716ab35947148f0.boutiques",
    name="new_invwarp",
    package="fsl",
    container_image_tag="mcin/fsl:6.0.5",
)


class NewInvwarpOutputs(typing.NamedTuple):
    """
    Output object returned when calling `new_invwarp(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType
    """Output inverse warped image"""


def new_invwarp(
    warp_file: InputPathType,
    out_file: str,
    ref_file: InputPathType,
    relative_warp_flag: bool = False,
    absolute_warp_flag: bool = False,
    no_constraint_flag: bool = False,
    min_jacobian: float | None = 0.01,
    max_jacobian: float | None = 100.0,
    debug_flag: bool = False,
    verbose_flag: bool = False,
    runner: Runner | None = None,
) -> NewInvwarpOutputs:
    """
    Tool for inverting warp fields in FSL.
    
    Author: University of Oxford (Jesper Andersson)
    
    URL: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FNIRT/UserGuide#Using_invwarp
    
    Args:
        warp_file: Filename for warp/shiftmap transform (volume).
        out_file: Filename for output (inverse warped) image.
        ref_file: Filename for new reference image, i.e., what was originally\
            the input image (determines inverse warpvol's FOV and pixdims).
        relative_warp_flag: Use relative warp convention: x' = x + w(x).
        absolute_warp_flag: Use absolute warp convention (default): x' = w(x).
        no_constraint_flag: Do not apply the Jacobian constraint.
        min_jacobian: Minimum acceptable Jacobian value for constraint (default\
            0.01).
        max_jacobian: Maximum acceptable Jacobian value for constraint (default\
            100.0).
        debug_flag: Turn on debugging output.
        verbose_flag: Switch on diagnostic messages.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `NewInvwarpOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(NEW_INVWARP_METADATA)
    cargs = []
    cargs.append("invwarp")
    cargs.append("--warp")
    cargs.extend([
        "--warp",
        execution.input_file(warp_file)
    ])
    cargs.append("--out")
    cargs.extend([
        "--out",
        out_file
    ])
    cargs.append("--ref")
    cargs.extend([
        "--ref",
        execution.input_file(ref_file)
    ])
    if relative_warp_flag:
        cargs.append("--rel")
    if absolute_warp_flag:
        cargs.append("--abs")
    if no_constraint_flag:
        cargs.append("--noconstraint")
    if min_jacobian is not None:
        cargs.extend([
            "--jmin",
            str(min_jacobian)
        ])
    if max_jacobian is not None:
        cargs.extend([
            "--jmax",
            str(max_jacobian)
        ])
    if debug_flag:
        cargs.append("--debug")
    if verbose_flag:
        cargs.append("--verbose")
    ret = NewInvwarpOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file(out_file),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "NEW_INVWARP_METADATA",
    "NewInvwarpOutputs",
    "new_invwarp",
]
