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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_3D_WARP_DRIVE_METADATA = Metadata(
    id="0c165837a84160290a1d8256b9238ca4ea37da6a.boutiques",
    name="3dWarpDrive",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V3dWarpDriveOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_3d_warp_drive(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_dataset: OutputPathType
    """Warped dataset output"""
    output_summary: OutputPathType | None
    """Summary of calculations"""
    oned_output_file: OutputPathType | None
    """File with warping parameters"""
    matrix_output_file: OutputPathType | None
    """File with transformation matrices"""


def v_3d_warp_drive(
    dataset: InputPathType,
    base_dataset: InputPathType,
    prefix: str,
    shift_only: bool = False,
    shift_rotate: bool = False,
    shift_rotate_scale: bool = False,
    affine_general: bool = False,
    bilinear_general: bool = False,
    linear: bool = False,
    cubic: bool = False,
    nn: bool = False,
    quintic: bool = False,
    input_dataset: InputPathType | None = None,
    verbosity_flag: bool = False,
    summary_file: str | None = None,
    max_iterations: int | None = None,
    delta: float | None = None,
    weight: str | None = None,
    convergence_thresh: float | None = None,
    twopass: bool = False,
    final_mode: str | None = None,
    parfix: list[str] | None = None,
    oned_file: InputPathType | None = None,
    float_format: bool = False,
    coarserot_init: bool = False,
    oned_matrix_save: InputPathType | None = None,
    sdu_order: bool = False,
    sud_order: bool = False,
    dsu_order: bool = False,
    dus_order: bool = False,
    usd_order: bool = False,
    uds_order: bool = False,
    supper_s_matrix: bool = False,
    slower_s_matrix: bool = False,
    ashift: bool = False,
    bshift: bool = False,
    runner: Runner | None = None,
) -> V3dWarpDriveOutputs:
    """
    Warp a dataset to match another one (the base) using an affine transformation.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        dataset: Input dataset.
        base_dataset: Load dataset as the base to which the input dataset will\
            be matched. This is a mandatory option.
        prefix: Sets the prefix of the output dataset. If 'NULL', no output\
            dataset is written.
        shift_only: 3 parameters (shifts).
        shift_rotate: 6 parameters (shifts + angles).
        shift_rotate_scale: 9 parameters (shifts + angles + scale factors).
        affine_general: 12 parameters (3 shifts + 3x3 matrix).
        bilinear_general: 39 parameters (3 + 3x3 + 3x3x3). Not implemented and\
            will never be.
        linear: Linear interpolation method.
        cubic: Cubic interpolation method.
        nn: Nearest neighbor interpolation method [default].
        quintic: Quintic interpolation method.
        input_dataset: Specify the input dataset anywhere in the command line\
            option list.
        verbosity_flag: Print out lots of information along the way.
        summary_file: Save summary of calculations into text file. If value is\
            '-', summary goes to stdout.
        max_iterations: Allow up to 'm' iterations for convergence.
        delta: Distance, in voxel size, used to compute image derivatives using\
            finite differences. [Default=1.0].
        weight: Set the weighting applied to each voxel proportional to the\
            brick specified here. [Default=computed by program from base].
        convergence_thresh: Set the convergence parameter to be RMS 't' voxels\
            movement between iterations. [Default=0.03].
        twopass: Do the parameter estimation in two passes, coarse-but-fast\
            first, then fine-but-slow second.
        final_mode: Set the final warp to be interpolated using 'mode'.
        parfix: Fix the n'th parameter of the warp model to the value 'v'. More\
            than one -parfix option can be used.
        oned_file: Write out the warping parameters to this file.
        float_format: Write output dataset in float format, even if input\
            dataset is short or byte.
        coarserot_init: Initialize shift+rotation parameters by a brute force\
            coarse search.
        oned_matrix_save: Save base-to-input transformation matrices in\
            specified file. If the file does not end in '.1D', the program will\
            append '.aff12.1D'.
        sdu_order: Set the order of the matrix multiplication for the affine\
            transformations (S=triangular shear, D=diagonal scaling matrix,\
            U=rotation matrix).
        sud_order: Set the order of the matrix multiplication for the affine\
            transformations (S=triangular shear, U=rotation matrix, D=diagonal\
            scaling matrix).
        dsu_order: Set the order of the matrix multiplication for the affine\
            transformations (D=diagonal scaling matrix, S=triangular shear,\
            U=rotation matrix).
        dus_order: Set the order of the matrix multiplication for the affine\
            transformations (D=diagonal scaling matrix, U=rotation matrix,\
            S=triangular shear).
        usd_order: Set the order of the matrix multiplication for the affine\
            transformations (U=rotation matrix, S=triangular shear, D=diagonal\
            scaling matrix).
        uds_order: Set the order of the matrix multiplication for the affine\
            transformations (U=rotation matrix, D=diagonal scaling matrix,\
            S=triangular shear).
        supper_s_matrix: Set the S matrix to be upper triangular.
        slower_s_matrix: Set the S matrix to be lower triangular.
        ashift: Apply the shift parameters after the matrix transformation.
        bshift: Apply the shift parameters before the matrix transformation.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V3dWarpDriveOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_3D_WARP_DRIVE_METADATA)
    cargs = []
    cargs.append("3dWarpDrive")
    cargs.append(execution.input_file(dataset))
    cargs.extend([
        "-base",
        execution.input_file(base_dataset)
    ])
    cargs.extend([
        "-prefix",
        prefix
    ])
    if shift_only:
        cargs.append("-shift_only")
    if shift_rotate:
        cargs.append("-shift_rotate")
    if shift_rotate_scale:
        cargs.append("-shift_rotate_scale")
    if affine_general:
        cargs.append("-affine_general")
    if bilinear_general:
        cargs.append("-bilinear_general")
    if linear:
        cargs.append("-linear")
    if cubic:
        cargs.append("-cubic")
    if nn:
        cargs.append("-NN")
    if quintic:
        cargs.append("-quintic")
    if input_dataset is not None:
        cargs.extend([
            "-input",
            execution.input_file(input_dataset)
        ])
    if verbosity_flag:
        cargs.append("-verb")
    if summary_file is not None:
        cargs.extend([
            "-summ",
            summary_file
        ])
    if max_iterations is not None:
        cargs.extend([
            "-maxite",
            str(max_iterations)
        ])
    if delta is not None:
        cargs.extend([
            "-delta",
            str(delta)
        ])
    if weight is not None:
        cargs.extend([
            "-weight",
            weight
        ])
    if convergence_thresh is not None:
        cargs.extend([
            "-thresh",
            str(convergence_thresh)
        ])
    if twopass:
        cargs.append("-twopass")
    if final_mode is not None:
        cargs.extend([
            "-final",
            final_mode
        ])
    if parfix is not None:
        cargs.extend([
            "-parfix",
            *parfix
        ])
    if oned_file is not None:
        cargs.extend([
            "-1Dfile",
            execution.input_file(oned_file)
        ])
    if float_format:
        cargs.append("-float")
    if coarserot_init:
        cargs.append("-coarserot")
    if oned_matrix_save is not None:
        cargs.extend([
            "-1Dmatrix_save",
            execution.input_file(oned_matrix_save)
        ])
    if sdu_order:
        cargs.append("-SDU")
    if sud_order:
        cargs.append("-SUD")
    if dsu_order:
        cargs.append("-DSU")
    if dus_order:
        cargs.append("-DUS")
    if usd_order:
        cargs.append("-USD")
    if uds_order:
        cargs.append("-UDS")
    if supper_s_matrix:
        cargs.append("-Supper")
    if slower_s_matrix:
        cargs.append("-Slower")
    if ashift:
        cargs.append("-ashift")
    if bshift:
        cargs.append("-bshift")
    ret = V3dWarpDriveOutputs(
        root=execution.output_file("."),
        output_dataset=execution.output_file(prefix + "+orig"),
        output_summary=execution.output_file(summary_file) if (summary_file is not None) else None,
        oned_output_file=execution.output_file(pathlib.Path(oned_file).name) if (oned_file is not None) else None,
        matrix_output_file=execution.output_file(pathlib.Path(oned_matrix_save).name) if (oned_matrix_save is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V3dWarpDriveOutputs",
    "V_3D_WARP_DRIVE_METADATA",
    "v_3d_warp_drive",
]
