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

import typing
import pathlib
from styxdefs import *
import dataclasses

ANTSUSE_DEFORMATION_FIELD_TO_GET_AFFINE_TRANSFORM_METADATA = Metadata(
    id="a114d5c9bfbab1242b558e6ff3e44480841f6e38.boutiques",
    name="ANTSUseDeformationFieldToGetAffineTransform",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


class AntsuseDeformationFieldToGetAffineTransformOutputs(typing.NamedTuple):
    """
    Output object returned when calling `antsuse_deformation_field_to_get_affine_transform(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_affine_txt: OutputPathType
    """The output is the affine transformation matrix file."""


def antsuse_deformation_field_to_get_affine_transform(
    deformation_field: InputPathType,
    load_ratio: float,
    transform_type: typing.Literal["rigid", "affine"],
    output_affine: str,
    mask: InputPathType | None = None,
    runner: Runner | None = None,
) -> AntsuseDeformationFieldToGetAffineTransformOutputs:
    """
    Extracts an affine transform from a deformation field. The input deformation
    field is expected to be in the same physical space as the images you want to
    transform.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        deformation_field: The input deformation field in NIfTI format (e.g.,\
            zzzWarp.nii.gz).
        load_ratio: Ratio of points to be loaded from deformation field to save\
            memory (ex: 0.01).
        transform_type: Type of transform to be extracted. Can be 'rigid' or\
            'affine'.
        output_affine: The output file where the affine transform will be saved\
            (e.g., OutAffine.txt).
        mask: Optional mask file defining the region from which points will be\
            selected.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsuseDeformationFieldToGetAffineTransformOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTSUSE_DEFORMATION_FIELD_TO_GET_AFFINE_TRANSFORM_METADATA)
    cargs = []
    cargs.append("ANTSUseDeformationFieldToGetAffineTransform")
    cargs.append(execution.input_file(deformation_field))
    cargs.append(str(load_ratio))
    cargs.append(transform_type)
    cargs.append(output_affine)
    if mask is not None:
        cargs.append(execution.input_file(mask))
    ret = AntsuseDeformationFieldToGetAffineTransformOutputs(
        root=execution.output_file("."),
        out_affine_txt=execution.output_file(output_affine),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "ANTSUSE_DEFORMATION_FIELD_TO_GET_AFFINE_TRANSFORM_METADATA",
    "AntsuseDeformationFieldToGetAffineTransformOutputs",
    "antsuse_deformation_field_to_get_affine_transform",
]
