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

import typing
import pathlib
from styxdefs import *

CREATE_WARPED_GRID_IMAGE_METADATA = Metadata(
    id="e77b860defec17e64141d0e139550e9625747193.boutiques",
    name="CreateWarpedGridImage",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_CreateWarpedGridImageParamsDictNoTag = typing.TypedDict('_CreateWarpedGridImageParamsDictNoTag', {
    "image_dimension": int,
    "deformation_field": InputPathType,
    "output_image": str,
    "directions": typing.NotRequired[str | None],
    "grid_spacing": typing.NotRequired[str | None],
    "grid_sigma": typing.NotRequired[str | None],
})
CreateWarpedGridImageParamsDictTagged = typing.TypedDict('CreateWarpedGridImageParamsDictTagged', {
    "@type": typing.Literal["ants/CreateWarpedGridImage"],
    "image_dimension": int,
    "deformation_field": InputPathType,
    "output_image": str,
    "directions": typing.NotRequired[str | None],
    "grid_spacing": typing.NotRequired[str | None],
    "grid_sigma": typing.NotRequired[str | None],
})
CreateWarpedGridImageParamsDict = _CreateWarpedGridImageParamsDictNoTag | CreateWarpedGridImageParamsDictTagged


class CreateWarpedGridImageOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CreateWarpedGridImageParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    warped_grid_image: OutputPathType
    """The resultant warped grid image."""


def create_warped_grid_image_params(
    image_dimension: int,
    deformation_field: InputPathType,
    output_image: str,
    directions: str | None = None,
    grid_spacing: str | None = None,
    grid_sigma: str | None = None,
) -> CreateWarpedGridImageParamsDictTagged:
    """
    Build parameters.
    
    Args:
        image_dimension: The dimensionality of the input image.
        deformation_field: File containing the deformation field to be applied.
        output_image: The filename of the output warped grid image.
        directions: Directions for the grid warping, e.g., '1x0x0'.
        grid_spacing: Spacing of the grid, e.g., '10x10x10'.
        grid_sigma: Sigma value for the grid smoothing, e.g., '1x1x1'.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/CreateWarpedGridImage",
        "image_dimension": image_dimension,
        "deformation_field": deformation_field,
        "output_image": output_image,
    }
    if directions is not None:
        params["directions"] = directions
    if grid_spacing is not None:
        params["grid_spacing"] = grid_spacing
    if grid_sigma is not None:
        params["grid_sigma"] = grid_sigma
    return params


def create_warped_grid_image_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CreateWarpedGridImageParamsDict` 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("image_dimension", None) is None:
        raise StyxValidationError("`image_dimension` must not be None")
    if not isinstance(params["image_dimension"], int):
        raise StyxValidationError(f'`image_dimension` has the wrong type: Received `{type(params.get("image_dimension", None))}` expected `int`')
    if params.get("deformation_field", None) is None:
        raise StyxValidationError("`deformation_field` must not be None")
    if not isinstance(params["deformation_field"], (pathlib.Path, str)):
        raise StyxValidationError(f'`deformation_field` has the wrong type: Received `{type(params.get("deformation_field", None))}` expected `InputPathType`')
    if params.get("output_image", None) is None:
        raise StyxValidationError("`output_image` must not be None")
    if not isinstance(params["output_image"], str):
        raise StyxValidationError(f'`output_image` has the wrong type: Received `{type(params.get("output_image", None))}` expected `str`')
    if params.get("directions", None) is not None:
        if not isinstance(params["directions"], str):
            raise StyxValidationError(f'`directions` has the wrong type: Received `{type(params.get("directions", None))}` expected `str | None`')
    if params.get("grid_spacing", None) is not None:
        if not isinstance(params["grid_spacing"], str):
            raise StyxValidationError(f'`grid_spacing` has the wrong type: Received `{type(params.get("grid_spacing", None))}` expected `str | None`')
    if params.get("grid_sigma", None) is not None:
        if not isinstance(params["grid_sigma"], str):
            raise StyxValidationError(f'`grid_sigma` has the wrong type: Received `{type(params.get("grid_sigma", None))}` expected `str | None`')


def create_warped_grid_image_cargs(
    params: CreateWarpedGridImageParamsDict,
    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("CreateWarpedGridImage")
    cargs.append(str(params.get("image_dimension", None)))
    cargs.append(execution.input_file(params.get("deformation_field", None)))
    cargs.append(params.get("output_image", None))
    if params.get("directions", None) is not None:
        cargs.append(params.get("directions", None))
    if params.get("grid_spacing", None) is not None:
        cargs.append(params.get("grid_spacing", None))
    if params.get("grid_sigma", None) is not None:
        cargs.append(params.get("grid_sigma", None))
    return cargs


def create_warped_grid_image_outputs(
    params: CreateWarpedGridImageParamsDict,
    execution: Execution,
) -> CreateWarpedGridImageOutputs:
    """
    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 = CreateWarpedGridImageOutputs(
        root=execution.output_file("."),
        warped_grid_image=execution.output_file(params.get("output_image", None)),
    )
    return ret


def create_warped_grid_image_execute(
    params: CreateWarpedGridImageParamsDict,
    runner: Runner | None = None,
) -> CreateWarpedGridImageOutputs:
    """
    CreateWarpedGridImage
    
    Create a warped grid image based on the specified deformation field.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CreateWarpedGridImageOutputs`).
    """
    create_warped_grid_image_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CREATE_WARPED_GRID_IMAGE_METADATA)
    params = execution.params(params)
    cargs = create_warped_grid_image_cargs(params, execution)
    ret = create_warped_grid_image_outputs(params, execution)
    execution.run(cargs)
    return ret


def create_warped_grid_image(
    image_dimension: int,
    deformation_field: InputPathType,
    output_image: str,
    directions: str | None = None,
    grid_spacing: str | None = None,
    grid_sigma: str | None = None,
    runner: Runner | None = None,
) -> CreateWarpedGridImageOutputs:
    """
    CreateWarpedGridImage
    
    Create a warped grid image based on the specified deformation field.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: The dimensionality of the input image.
        deformation_field: File containing the deformation field to be applied.
        output_image: The filename of the output warped grid image.
        directions: Directions for the grid warping, e.g., '1x0x0'.
        grid_spacing: Spacing of the grid, e.g., '10x10x10'.
        grid_sigma: Sigma value for the grid smoothing, e.g., '1x1x1'.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CreateWarpedGridImageOutputs`).
    """
    params = create_warped_grid_image_params(
        image_dimension=image_dimension,
        deformation_field=deformation_field,
        output_image=output_image,
        directions=directions,
        grid_spacing=grid_spacing,
        grid_sigma=grid_sigma,
    )
    return create_warped_grid_image_execute(params, runner)


__all__ = [
    "CREATE_WARPED_GRID_IMAGE_METADATA",
    "CreateWarpedGridImageOutputs",
    "CreateWarpedGridImageParamsDict",
    "CreateWarpedGridImageParamsDictTagged",
    "create_warped_grid_image",
    "create_warped_grid_image_execute",
    "create_warped_grid_image_params",
]
