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

import typing
import pathlib
from styxdefs import *

ANTS_LANDMARK_BASED_TRANSFORM_INITIALIZER_METADATA = Metadata(
    id="e3b5bf9f02ef1ef7f7316f607332292a3b1568a6.boutiques",
    name="antsLandmarkBasedTransformInitializer",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_AntsLandmarkBasedTransformInitializerParamsDictNoTag = typing.TypedDict('_AntsLandmarkBasedTransformInitializerParamsDictNoTag', {
    "dimension": int,
    "fixed_image": InputPathType,
    "moving_image": InputPathType,
    "transform_type": typing.Literal["rigid", "affine", "bspline"],
    "output_transform": str,
    "mesh_size": typing.NotRequired[str | None],
    "number_of_levels": typing.NotRequired[int | None],
    "order": typing.NotRequired[int | None],
    "enforce_stationary_boundaries": typing.NotRequired[bool | None],
    "landmark_weights": typing.NotRequired[InputPathType | None],
})
AntsLandmarkBasedTransformInitializerParamsDictTagged = typing.TypedDict('AntsLandmarkBasedTransformInitializerParamsDictTagged', {
    "@type": typing.Literal["ants/antsLandmarkBasedTransformInitializer"],
    "dimension": int,
    "fixed_image": InputPathType,
    "moving_image": InputPathType,
    "transform_type": typing.Literal["rigid", "affine", "bspline"],
    "output_transform": str,
    "mesh_size": typing.NotRequired[str | None],
    "number_of_levels": typing.NotRequired[int | None],
    "order": typing.NotRequired[int | None],
    "enforce_stationary_boundaries": typing.NotRequired[bool | None],
    "landmark_weights": typing.NotRequired[InputPathType | None],
})
AntsLandmarkBasedTransformInitializerParamsDict = _AntsLandmarkBasedTransformInitializerParamsDictNoTag | AntsLandmarkBasedTransformInitializerParamsDictTagged


class AntsLandmarkBasedTransformInitializerOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AntsLandmarkBasedTransformInitializerParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_transform: OutputPathType
    """The output file containing the initialized transform."""


def ants_landmark_based_transform_initializer_params(
    dimension: int,
    fixed_image: InputPathType,
    moving_image: InputPathType,
    transform_type: typing.Literal["rigid", "affine", "bspline"],
    output_transform: str,
    mesh_size: str | None = None,
    number_of_levels: int | None = None,
    order: int | None = None,
    enforce_stationary_boundaries: bool | None = None,
    landmark_weights: InputPathType | None = None,
) -> AntsLandmarkBasedTransformInitializerParamsDictTagged:
    """
    Build parameters.
    
    Args:
        dimension: The dimensionality of the registration problem (e.g., 2 for\
            2D, 3 for 3D).
        fixed_image: The fixed image in the registration process.
        moving_image: The moving image in the registration process.
        transform_type: The type of transform to initialize. Options are\
            'rigid', 'affine', or 'bspline'.
        output_transform: The output transform file that will be created.
        mesh_size: The mesh size for the B-spline transform, specified as\
            'meshSize[0]xmeshSize[1]x...'. Default is '1x1x1'.
        number_of_levels: Number of levels for multi-resolution fitting.\
            Default is 4.
        order: The polynomial order of the B-spline transform. Default is 3.
        enforce_stationary_boundaries: Enforces stationary boundaries for the\
            B-spline transform. Default is 1 (true).
        landmark_weights: File containing landmark weights. Each row is either\
            'label,labelWeight' or 'labelWeight'.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/antsLandmarkBasedTransformInitializer",
        "dimension": dimension,
        "fixed_image": fixed_image,
        "moving_image": moving_image,
        "transform_type": transform_type,
        "output_transform": output_transform,
    }
    if mesh_size is not None:
        params["mesh_size"] = mesh_size
    if number_of_levels is not None:
        params["number_of_levels"] = number_of_levels
    if order is not None:
        params["order"] = order
    if enforce_stationary_boundaries is not None:
        params["enforce_stationary_boundaries"] = enforce_stationary_boundaries
    if landmark_weights is not None:
        params["landmark_weights"] = landmark_weights
    return params


def ants_landmark_based_transform_initializer_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsLandmarkBasedTransformInitializerParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("dimension", None) is None:
        raise StyxValidationError("`dimension` must not be None")
    if not isinstance(params["dimension"], int):
        raise StyxValidationError(f'`dimension` has the wrong type: Received `{type(params.get("dimension", None))}` expected `int`')
    if params.get("fixed_image", None) is None:
        raise StyxValidationError("`fixed_image` must not be None")
    if not isinstance(params["fixed_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`fixed_image` has the wrong type: Received `{type(params.get("fixed_image", None))}` expected `InputPathType`')
    if params.get("moving_image", None) is None:
        raise StyxValidationError("`moving_image` must not be None")
    if not isinstance(params["moving_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`moving_image` has the wrong type: Received `{type(params.get("moving_image", None))}` expected `InputPathType`')
    if params.get("transform_type", None) is None:
        raise StyxValidationError("`transform_type` must not be None")
    if not isinstance(params["transform_type"], str):
        raise StyxValidationError(f'`transform_type` has the wrong type: Received `{type(params.get("transform_type", None))}` expected `typing.Literal["rigid", "affine", "bspline"]`')
    if params["transform_type"] not in ["rigid", "affine", "bspline"]:
        raise StyxValidationError("Parameter `transform_type` must be one of [\"rigid\", \"affine\", \"bspline\"]")
    if params.get("output_transform", None) is None:
        raise StyxValidationError("`output_transform` must not be None")
    if not isinstance(params["output_transform"], str):
        raise StyxValidationError(f'`output_transform` has the wrong type: Received `{type(params.get("output_transform", None))}` expected `str`')
    if params.get("mesh_size", None) is not None:
        if not isinstance(params["mesh_size"], str):
            raise StyxValidationError(f'`mesh_size` has the wrong type: Received `{type(params.get("mesh_size", None))}` expected `str | None`')
    if params.get("number_of_levels", None) is not None:
        if not isinstance(params["number_of_levels"], int):
            raise StyxValidationError(f'`number_of_levels` has the wrong type: Received `{type(params.get("number_of_levels", None))}` expected `int | None`')
    if params.get("order", None) is not None:
        if not isinstance(params["order"], int):
            raise StyxValidationError(f'`order` has the wrong type: Received `{type(params.get("order", None))}` expected `int | None`')
    if params.get("enforce_stationary_boundaries", None) is not None:
        if not isinstance(params["enforce_stationary_boundaries"], bool):
            raise StyxValidationError(f'`enforce_stationary_boundaries` has the wrong type: Received `{type(params.get("enforce_stationary_boundaries", None))}` expected `bool | None`')
    if params.get("landmark_weights", None) is not None:
        if not isinstance(params["landmark_weights"], (pathlib.Path, str)):
            raise StyxValidationError(f'`landmark_weights` has the wrong type: Received `{type(params.get("landmark_weights", None))}` expected `InputPathType | None`')


def ants_landmark_based_transform_initializer_cargs(
    params: AntsLandmarkBasedTransformInitializerParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("antsLandmarkBasedTransformInitializer")
    cargs.append(str(params.get("dimension", None)))
    cargs.append(execution.input_file(params.get("fixed_image", None)))
    cargs.append(execution.input_file(params.get("moving_image", None)))
    cargs.append(params.get("transform_type", None))
    cargs.append(params.get("output_transform", None))
    if params.get("mesh_size", None) is not None:
        cargs.append(params.get("mesh_size", None))
    if params.get("number_of_levels", None) is not None:
        cargs.append(str(params.get("number_of_levels", None)))
    if params.get("order", None) is not None:
        cargs.append(str(params.get("order", None)))
    if params.get("enforce_stationary_boundaries", None) is not None:
        cargs.append(("1" if params.get("enforce_stationary_boundaries", None) else "0"))
    if params.get("landmark_weights", None) is not None:
        cargs.append(execution.input_file(params.get("landmark_weights", None)))
    return cargs


def ants_landmark_based_transform_initializer_outputs(
    params: AntsLandmarkBasedTransformInitializerParamsDict,
    execution: Execution,
) -> AntsLandmarkBasedTransformInitializerOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = AntsLandmarkBasedTransformInitializerOutputs(
        root=execution.output_file("."),
        output_transform=execution.output_file(params.get("output_transform", None)),
    )
    return ret


def ants_landmark_based_transform_initializer_execute(
    params: AntsLandmarkBasedTransformInitializerParamsDict,
    runner: Runner | None = None,
) -> AntsLandmarkBasedTransformInitializerOutputs:
    """
    antsLandmarkBasedTransformInitializer
    
    This tool initializes a transform between two images based on corresponding
    landmarks.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsLandmarkBasedTransformInitializerOutputs`).
    """
    ants_landmark_based_transform_initializer_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTS_LANDMARK_BASED_TRANSFORM_INITIALIZER_METADATA)
    params = execution.params(params)
    cargs = ants_landmark_based_transform_initializer_cargs(params, execution)
    ret = ants_landmark_based_transform_initializer_outputs(params, execution)
    execution.run(cargs)
    return ret


def ants_landmark_based_transform_initializer(
    dimension: int,
    fixed_image: InputPathType,
    moving_image: InputPathType,
    transform_type: typing.Literal["rigid", "affine", "bspline"],
    output_transform: str,
    mesh_size: str | None = None,
    number_of_levels: int | None = None,
    order: int | None = None,
    enforce_stationary_boundaries: bool | None = None,
    landmark_weights: InputPathType | None = None,
    runner: Runner | None = None,
) -> AntsLandmarkBasedTransformInitializerOutputs:
    """
    antsLandmarkBasedTransformInitializer
    
    This tool initializes a transform between two images based on corresponding
    landmarks.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        dimension: The dimensionality of the registration problem (e.g., 2 for\
            2D, 3 for 3D).
        fixed_image: The fixed image in the registration process.
        moving_image: The moving image in the registration process.
        transform_type: The type of transform to initialize. Options are\
            'rigid', 'affine', or 'bspline'.
        output_transform: The output transform file that will be created.
        mesh_size: The mesh size for the B-spline transform, specified as\
            'meshSize[0]xmeshSize[1]x...'. Default is '1x1x1'.
        number_of_levels: Number of levels for multi-resolution fitting.\
            Default is 4.
        order: The polynomial order of the B-spline transform. Default is 3.
        enforce_stationary_boundaries: Enforces stationary boundaries for the\
            B-spline transform. Default is 1 (true).
        landmark_weights: File containing landmark weights. Each row is either\
            'label,labelWeight' or 'labelWeight'.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsLandmarkBasedTransformInitializerOutputs`).
    """
    params = ants_landmark_based_transform_initializer_params(
        dimension=dimension,
        fixed_image=fixed_image,
        moving_image=moving_image,
        transform_type=transform_type,
        output_transform=output_transform,
        mesh_size=mesh_size,
        number_of_levels=number_of_levels,
        order=order,
        enforce_stationary_boundaries=enforce_stationary_boundaries,
        landmark_weights=landmark_weights,
    )
    return ants_landmark_based_transform_initializer_execute(params, runner)


__all__ = [
    "ANTS_LANDMARK_BASED_TRANSFORM_INITIALIZER_METADATA",
    "AntsLandmarkBasedTransformInitializerOutputs",
    "AntsLandmarkBasedTransformInitializerParamsDict",
    "AntsLandmarkBasedTransformInitializerParamsDictTagged",
    "ants_landmark_based_transform_initializer",
    "ants_landmark_based_transform_initializer_execute",
    "ants_landmark_based_transform_initializer_params",
]
