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

import typing
import pathlib
from styxdefs import *
import dataclasses

CONVERTWARP_METADATA = Metadata(
    id="72b8c95c9bb70bd2c1483db87cbd13ddbdf4d26c.boutiques",
    name="convertwarp",
    package="fsl",
    container_image_tag="mcin/fsl:6.0.5",
)


class ConvertwarpOutputs(typing.NamedTuple):
    """
    Output object returned when calling `convertwarp(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_warp_file: OutputPathType
    """Output warp image"""


def convertwarp(
    output_warp: str,
    refvol: InputPathType,
    premat: InputPathType | None = None,
    warp1: InputPathType | None = None,
    midmat: InputPathType | None = None,
    warp2: InputPathType | None = None,
    postmat: InputPathType | None = None,
    shiftmap: InputPathType | None = None,
    shiftdir: typing.Literal["x", "y", "z", "x-", "y-", "z-"] | None = None,
    jacobian: bool = False,
    jstats: bool = False,
    constrainj: bool = False,
    jmin: float | None = None,
    jmax: float | None = None,
    abs_: bool = False,
    rel: bool = False,
    absout: bool = False,
    relout: bool = False,
    verbose: bool = False,
    runner: Runner | None = None,
) -> ConvertwarpOutputs:
    """
    Convert and combine FSL warp fields.
    
    Author: University of Oxford
    
    URL: https://fsl.fmrib.ox.ac.uk
    
    Args:
        output_warp: Filename for output (warp) image - always in 'field'\
            format.
        refvol: Filename for reference image.
        premat: Filename of pre-affine transform.
        warp1: Filename for initial warp (follows pre-affine).
        midmat: Filename of mid-warp-affine transform.
        warp2: Filename for secondary warp (after initial warp, before\
            post-affine).
        postmat: Filename of post-affine transform.
        shiftmap: Filename for shiftmap (applied first).
        shiftdir: Direction to apply shiftmap {x,y,z,x-,y-,z-}.
        jacobian: Calculate and save Jacobian of final warp field.
        jstats: Print out statistics of the Jacobian of the warpfield.
        constrainj: Constrain the Jacobian of the warpfield to lie within\
            specified min/max limits.
        jmin: Minimum acceptable Jacobian value for constraint (default 0.01).
        jmax: Maximum acceptable Jacobian value for constraint (default 100.0).
        abs_: Use absolute warp convention (default): x' = w(x).
        rel: Use relative warp convention: x' = x + w(x).
        absout: Force output to use absolute warp convention: x' = w(x).
        relout: Force output to use relative warp convention: x' = x + w(x).
        verbose: Switch on diagnostic messages.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ConvertwarpOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CONVERTWARP_METADATA)
    cargs = []
    cargs.append("convertwarp")
    cargs.extend([
        "-o",
        output_warp
    ])
    cargs.extend([
        "-r",
        execution.input_file(refvol)
    ])
    if premat is not None:
        cargs.extend([
            "-m",
            execution.input_file(premat)
        ])
    if warp1 is not None:
        cargs.extend([
            "-w",
            execution.input_file(warp1)
        ])
    if midmat is not None:
        cargs.extend([
            "--midmat",
            execution.input_file(midmat)
        ])
    if warp2 is not None:
        cargs.extend([
            "--warp2",
            execution.input_file(warp2)
        ])
    if postmat is not None:
        cargs.extend([
            "--postmat",
            execution.input_file(postmat)
        ])
    if shiftmap is not None:
        cargs.extend([
            "-s",
            execution.input_file(shiftmap)
        ])
    if shiftdir is not None:
        cargs.extend([
            "-d",
            shiftdir
        ])
    if jacobian:
        cargs.append("-j")
    if jstats:
        cargs.append("--jstats")
    if constrainj:
        cargs.append("--constrainj")
    if jmin is not None:
        cargs.extend([
            "--jmin",
            str(jmin)
        ])
    if jmax is not None:
        cargs.extend([
            "--jmax",
            str(jmax)
        ])
    if abs_:
        cargs.append("--abs")
    if rel:
        cargs.append("--rel")
    if absout:
        cargs.append("--absout")
    if relout:
        cargs.append("--relout")
    if verbose:
        cargs.append("-v")
    ret = ConvertwarpOutputs(
        root=execution.output_file("."),
        output_warp_file=execution.output_file(output_warp),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "CONVERTWARP_METADATA",
    "ConvertwarpOutputs",
    "convertwarp",
]
