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

import typing
import pathlib
from styxdefs import *

ANTSUSE_LANDMARK_IMAGES_TO_GET_BSPLINE_DISPLACEMENT_FIELD_METADATA = Metadata(
    id="97a7208c0feb66caac1f85f91d7e5b2be53f6438.boutiques",
    name="ANTSUseLandmarkImagesToGetBSplineDisplacementField",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDictNoTag = typing.TypedDict('_AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDictNoTag', {
    "fixed_image_with_labeled_landmarks": InputPathType,
    "moving_image_with_labeled_landmarks": InputPathType,
    "output_displacement_field": str,
    "mesh_size": str,
    "number_of_levels": int,
    "order": typing.NotRequired[int | None],
    "enforce_stationary_boundaries": typing.NotRequired[int | None],
    "landmark_weights": typing.NotRequired[InputPathType | None],
})
AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDictTagged = typing.TypedDict('AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDictTagged', {
    "@type": typing.Literal["ants/ANTSUseLandmarkImagesToGetBSplineDisplacementField"],
    "fixed_image_with_labeled_landmarks": InputPathType,
    "moving_image_with_labeled_landmarks": InputPathType,
    "output_displacement_field": str,
    "mesh_size": str,
    "number_of_levels": int,
    "order": typing.NotRequired[int | None],
    "enforce_stationary_boundaries": typing.NotRequired[int | None],
    "landmark_weights": typing.NotRequired[InputPathType | None],
})
AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDict = _AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDictNoTag | AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDictTagged


class AntsuseLandmarkImagesToGetBsplineDisplacementFieldOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    displacement_field: OutputPathType
    """The resultant displacement field for the registration process."""


def antsuse_landmark_images_to_get_bspline_displacement_field_params(
    fixed_image_with_labeled_landmarks: InputPathType,
    moving_image_with_labeled_landmarks: InputPathType,
    output_displacement_field: str,
    mesh_size: str,
    number_of_levels: int,
    order: int | None = None,
    enforce_stationary_boundaries: int | None = None,
    landmark_weights: InputPathType | None = None,
) -> AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDictTagged:
    """
    Build parameters.
    
    Args:
        fixed_image_with_labeled_landmarks: The fixed image with labeled\
            landmarks.
        moving_image_with_labeled_landmarks: The moving image with labeled\
            landmarks.
        output_displacement_field: The output displacement field file.
        mesh_size: The mesh size specified as meshSize[0]xmeshSize[1]x...
        number_of_levels: The number of levels in the B-spline hierarchy.
        order: The order of the B-spline (default is 3).
        enforce_stationary_boundaries: Whether to enforce stationary boundaries\
            (default is 1).
        landmark_weights: Optional text file containing landmark weights. Each\
            row is either "label,labelWeight" or "labelWeight". If the latter\
            format is used, the weights are assumed to be arranged in ascending\
            order by label.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/ANTSUseLandmarkImagesToGetBSplineDisplacementField",
        "fixed_image_with_labeled_landmarks": fixed_image_with_labeled_landmarks,
        "moving_image_with_labeled_landmarks": moving_image_with_labeled_landmarks,
        "output_displacement_field": output_displacement_field,
        "mesh_size": mesh_size,
        "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 antsuse_landmark_images_to_get_bspline_displacement_field_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDict` 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("fixed_image_with_labeled_landmarks", None) is None:
        raise StyxValidationError("`fixed_image_with_labeled_landmarks` must not be None")
    if not isinstance(params["fixed_image_with_labeled_landmarks"], (pathlib.Path, str)):
        raise StyxValidationError(f'`fixed_image_with_labeled_landmarks` has the wrong type: Received `{type(params.get("fixed_image_with_labeled_landmarks", None))}` expected `InputPathType`')
    if params.get("moving_image_with_labeled_landmarks", None) is None:
        raise StyxValidationError("`moving_image_with_labeled_landmarks` must not be None")
    if not isinstance(params["moving_image_with_labeled_landmarks"], (pathlib.Path, str)):
        raise StyxValidationError(f'`moving_image_with_labeled_landmarks` has the wrong type: Received `{type(params.get("moving_image_with_labeled_landmarks", None))}` expected `InputPathType`')
    if params.get("output_displacement_field", None) is None:
        raise StyxValidationError("`output_displacement_field` must not be None")
    if not isinstance(params["output_displacement_field"], str):
        raise StyxValidationError(f'`output_displacement_field` has the wrong type: Received `{type(params.get("output_displacement_field", None))}` expected `str`')
    if params.get("mesh_size", None) is None:
        raise StyxValidationError("`mesh_size` must not be 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`')
    if params.get("number_of_levels", None) is None:
        raise StyxValidationError("`number_of_levels` must not be 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`')
    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"], int):
            raise StyxValidationError(f'`enforce_stationary_boundaries` has the wrong type: Received `{type(params.get("enforce_stationary_boundaries", None))}` expected `int | 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 antsuse_landmark_images_to_get_bspline_displacement_field_cargs(
    params: AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDict,
    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("ANTSUseLandmarkImagesToGetBSplineDisplacementField")
    cargs.append(execution.input_file(params.get("fixed_image_with_labeled_landmarks", None)))
    cargs.append(execution.input_file(params.get("moving_image_with_labeled_landmarks", None)))
    cargs.append(params.get("output_displacement_field", None))
    cargs.append(params.get("mesh_size", 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(str(params.get("enforce_stationary_boundaries", None)))
    if params.get("landmark_weights", None) is not None:
        cargs.append(execution.input_file(params.get("landmark_weights", None)))
    return cargs


def antsuse_landmark_images_to_get_bspline_displacement_field_outputs(
    params: AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDict,
    execution: Execution,
) -> AntsuseLandmarkImagesToGetBsplineDisplacementFieldOutputs:
    """
    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 = AntsuseLandmarkImagesToGetBsplineDisplacementFieldOutputs(
        root=execution.output_file("."),
        displacement_field=execution.output_file(params.get("output_displacement_field", None)),
    )
    return ret


def antsuse_landmark_images_to_get_bspline_displacement_field_execute(
    params: AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDict,
    runner: Runner | None = None,
) -> AntsuseLandmarkImagesToGetBsplineDisplacementFieldOutputs:
    """
    ANTSUseLandmarkImagesToGetBSplineDisplacementField
    
    We expect the input images to be (1) N-ary (2) in the same physical space as
    the images you want to register and (3) to have the same landmark points
    defined within them. Landmarks will be defined from the center of mass of
    the labels in the input images. You can use ITK-snap to generate the label
    images. The optional landmarks weights are read from a text file where each
    row is either: "label,labelWeight" or "labelWeight". If the latter format is
    used, the label weights are assumed to be arranged in ascending order by
    label.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsuseLandmarkImagesToGetBsplineDisplacementFieldOutputs`).
    """
    antsuse_landmark_images_to_get_bspline_displacement_field_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTSUSE_LANDMARK_IMAGES_TO_GET_BSPLINE_DISPLACEMENT_FIELD_METADATA)
    params = execution.params(params)
    cargs = antsuse_landmark_images_to_get_bspline_displacement_field_cargs(params, execution)
    ret = antsuse_landmark_images_to_get_bspline_displacement_field_outputs(params, execution)
    execution.run(cargs)
    return ret


def antsuse_landmark_images_to_get_bspline_displacement_field(
    fixed_image_with_labeled_landmarks: InputPathType,
    moving_image_with_labeled_landmarks: InputPathType,
    output_displacement_field: str,
    mesh_size: str,
    number_of_levels: int,
    order: int | None = None,
    enforce_stationary_boundaries: int | None = None,
    landmark_weights: InputPathType | None = None,
    runner: Runner | None = None,
) -> AntsuseLandmarkImagesToGetBsplineDisplacementFieldOutputs:
    """
    ANTSUseLandmarkImagesToGetBSplineDisplacementField
    
    We expect the input images to be (1) N-ary (2) in the same physical space as
    the images you want to register and (3) to have the same landmark points
    defined within them. Landmarks will be defined from the center of mass of
    the labels in the input images. You can use ITK-snap to generate the label
    images. The optional landmarks weights are read from a text file where each
    row is either: "label,labelWeight" or "labelWeight". If the latter format is
    used, the label weights are assumed to be arranged in ascending order by
    label.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        fixed_image_with_labeled_landmarks: The fixed image with labeled\
            landmarks.
        moving_image_with_labeled_landmarks: The moving image with labeled\
            landmarks.
        output_displacement_field: The output displacement field file.
        mesh_size: The mesh size specified as meshSize[0]xmeshSize[1]x...
        number_of_levels: The number of levels in the B-spline hierarchy.
        order: The order of the B-spline (default is 3).
        enforce_stationary_boundaries: Whether to enforce stationary boundaries\
            (default is 1).
        landmark_weights: Optional text file containing landmark weights. Each\
            row is either "label,labelWeight" or "labelWeight". If the latter\
            format is used, the weights are assumed to be arranged in ascending\
            order by label.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsuseLandmarkImagesToGetBsplineDisplacementFieldOutputs`).
    """
    params = antsuse_landmark_images_to_get_bspline_displacement_field_params(
        fixed_image_with_labeled_landmarks=fixed_image_with_labeled_landmarks,
        moving_image_with_labeled_landmarks=moving_image_with_labeled_landmarks,
        output_displacement_field=output_displacement_field,
        mesh_size=mesh_size,
        number_of_levels=number_of_levels,
        order=order,
        enforce_stationary_boundaries=enforce_stationary_boundaries,
        landmark_weights=landmark_weights,
    )
    return antsuse_landmark_images_to_get_bspline_displacement_field_execute(params, runner)


__all__ = [
    "ANTSUSE_LANDMARK_IMAGES_TO_GET_BSPLINE_DISPLACEMENT_FIELD_METADATA",
    "AntsuseLandmarkImagesToGetBsplineDisplacementFieldOutputs",
    "AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDict",
    "AntsuseLandmarkImagesToGetBsplineDisplacementFieldParamsDictTagged",
    "antsuse_landmark_images_to_get_bspline_displacement_field",
    "antsuse_landmark_images_to_get_bspline_displacement_field_execute",
    "antsuse_landmark_images_to_get_bspline_displacement_field_params",
]
