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

import typing
import pathlib
from styxdefs import *

CREATE_TILED_MOSAIC_METADATA = Metadata(
    id="ce3fc57fea426a71907429b635a0ccf43f34f6db.boutiques",
    name="CreateTiledMosaic",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_CreateTiledMosaicParamsDictNoTag = typing.TypedDict('_CreateTiledMosaicParamsDictNoTag', {
    "input_image": InputPathType,
    "rgb_image": typing.NotRequired[InputPathType | None],
    "mask_image": typing.NotRequired[InputPathType | None],
    "alpha": typing.NotRequired[float | None],
    "functional_overlay": typing.NotRequired[str | None],
    "output": str,
    "tile_geometry": typing.NotRequired[str | None],
    "direction": typing.NotRequired[typing.Literal["0", "1", "2", "x", "y", "z"] | None],
    "pad_or_crop": typing.NotRequired[str | None],
    "slices": typing.NotRequired[str | None],
    "flip_slice": typing.NotRequired[str | None],
    "permute_axes": typing.NotRequired[bool | None],
})
CreateTiledMosaicParamsDictTagged = typing.TypedDict('CreateTiledMosaicParamsDictTagged', {
    "@type": typing.Literal["ants/CreateTiledMosaic"],
    "input_image": InputPathType,
    "rgb_image": typing.NotRequired[InputPathType | None],
    "mask_image": typing.NotRequired[InputPathType | None],
    "alpha": typing.NotRequired[float | None],
    "functional_overlay": typing.NotRequired[str | None],
    "output": str,
    "tile_geometry": typing.NotRequired[str | None],
    "direction": typing.NotRequired[typing.Literal["0", "1", "2", "x", "y", "z"] | None],
    "pad_or_crop": typing.NotRequired[str | None],
    "slices": typing.NotRequired[str | None],
    "flip_slice": typing.NotRequired[str | None],
    "permute_axes": typing.NotRequired[bool | None],
})
CreateTiledMosaicParamsDict = _CreateTiledMosaicParamsDictNoTag | CreateTiledMosaicParamsDictTagged


class CreateTiledMosaicOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CreateTiledMosaicParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    tiled_mosaic_image: OutputPathType
    """The output is the tiled mosaic image."""


def create_tiled_mosaic_params(
    input_image: InputPathType,
    output: str,
    rgb_image: InputPathType | None = None,
    mask_image: InputPathType | None = None,
    alpha: float | None = None,
    functional_overlay: str | None = None,
    tile_geometry: str | None = None,
    direction: typing.Literal["0", "1", "2", "x", "y", "z"] | None = None,
    pad_or_crop: str | None = None,
    slices: str | None = None,
    flip_slice: str | None = None,
    permute_axes: bool | None = None,
) -> CreateTiledMosaicParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_image: Main input is a 3-D grayscale image.
        output: The output is the tiled mosaic image. The format must support\
            the specific data type: floating point images without RGB overlays, Rgb\
            images with intensities scaled to [0,255] if overlays are present.
        rgb_image: An optional Rgb image can be added as an overlay. It must\
            have the same image geometry as the input grayscale image.
        mask_image: Specifies the ROI of the RGB voxels used.
        alpha: If an Rgb image is provided, render the overlay using the\
            specified alpha parameter.
        functional_overlay: A functional overlay can be specified using both\
            and rgb image and a mask specifying where that rgb image should be\
            applied. Both images must have the same image geometry as the input\
            image. Optionally, an alpha parameter can be specified.
        tile_geometry: The tile geometry specifies the number of rows and\
            columns in the output image. For example, specifying '5x10' renders 5\
            rows by 10 columns of slices.
        direction: Specifies the direction of the slices. Can be based on image\
            storage in memory or aligned physical space. Defaults to z-direction if\
            unspecified.
        pad_or_crop: Specify padding or cropping with a voxel-width boundary\
            for each slice. Padding uses a specified constant value. Cropping pads\
            with negative voxel-widths.
        slices: Control over which slices to render. Specify slices directly or\
            incrementally with optional start and end slices.
        flip_slice: Flip individual slice images horizontally and/or\
            vertically.
        permute_axes: Permute (or swap) the axes of the individual slice\
            images.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/CreateTiledMosaic",
        "input_image": input_image,
        "output": output,
    }
    if rgb_image is not None:
        params["rgb_image"] = rgb_image
    if mask_image is not None:
        params["mask_image"] = mask_image
    if alpha is not None:
        params["alpha"] = alpha
    if functional_overlay is not None:
        params["functional_overlay"] = functional_overlay
    if tile_geometry is not None:
        params["tile_geometry"] = tile_geometry
    if direction is not None:
        params["direction"] = direction
    if pad_or_crop is not None:
        params["pad_or_crop"] = pad_or_crop
    if slices is not None:
        params["slices"] = slices
    if flip_slice is not None:
        params["flip_slice"] = flip_slice
    if permute_axes is not None:
        params["permute_axes"] = permute_axes
    return params


def create_tiled_mosaic_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CreateTiledMosaicParamsDict` 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("input_image", None) is None:
        raise StyxValidationError("`input_image` must not be None")
    if not isinstance(params["input_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input_image` has the wrong type: Received `{type(params.get("input_image", None))}` expected `InputPathType`')
    if params.get("rgb_image", None) is not None:
        if not isinstance(params["rgb_image"], (pathlib.Path, str)):
            raise StyxValidationError(f'`rgb_image` has the wrong type: Received `{type(params.get("rgb_image", None))}` expected `InputPathType | None`')
    if params.get("mask_image", None) is not None:
        if not isinstance(params["mask_image"], (pathlib.Path, str)):
            raise StyxValidationError(f'`mask_image` has the wrong type: Received `{type(params.get("mask_image", None))}` expected `InputPathType | None`')
    if params.get("alpha", None) is not None:
        if not isinstance(params["alpha"], (float, int)):
            raise StyxValidationError(f'`alpha` has the wrong type: Received `{type(params.get("alpha", None))}` expected `float | None`')
    if params.get("functional_overlay", None) is not None:
        if not isinstance(params["functional_overlay"], str):
            raise StyxValidationError(f'`functional_overlay` has the wrong type: Received `{type(params.get("functional_overlay", None))}` expected `str | None`')
    if params.get("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')
    if params.get("tile_geometry", None) is not None:
        if not isinstance(params["tile_geometry"], str):
            raise StyxValidationError(f'`tile_geometry` has the wrong type: Received `{type(params.get("tile_geometry", None))}` expected `str | None`')
    if params.get("direction", None) is not None:
        if not isinstance(params["direction"], str):
            raise StyxValidationError(f'`direction` has the wrong type: Received `{type(params.get("direction", None))}` expected `typing.Literal["0", "1", "2", "x", "y", "z"] | None`')
        if params["direction"] not in ["0", "1", "2", "x", "y", "z"]:
            raise StyxValidationError("Parameter `direction` must be one of [\"0\", \"1\", \"2\", \"x\", \"y\", \"z\"]")
    if params.get("pad_or_crop", None) is not None:
        if not isinstance(params["pad_or_crop"], str):
            raise StyxValidationError(f'`pad_or_crop` has the wrong type: Received `{type(params.get("pad_or_crop", None))}` expected `str | None`')
    if params.get("slices", None) is not None:
        if not isinstance(params["slices"], str):
            raise StyxValidationError(f'`slices` has the wrong type: Received `{type(params.get("slices", None))}` expected `str | None`')
    if params.get("flip_slice", None) is not None:
        if not isinstance(params["flip_slice"], str):
            raise StyxValidationError(f'`flip_slice` has the wrong type: Received `{type(params.get("flip_slice", None))}` expected `str | None`')
    if params.get("permute_axes", None) is not None:
        if not isinstance(params["permute_axes"], bool):
            raise StyxValidationError(f'`permute_axes` has the wrong type: Received `{type(params.get("permute_axes", None))}` expected `bool | None`')


def create_tiled_mosaic_cargs(
    params: CreateTiledMosaicParamsDict,
    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("CreateTiledMosaic")
    cargs.extend([
        "-i",
        execution.input_file(params.get("input_image", None))
    ])
    if params.get("rgb_image", None) is not None:
        cargs.extend([
            "-r",
            execution.input_file(params.get("rgb_image", None))
        ])
    if params.get("mask_image", None) is not None:
        cargs.extend([
            "-x",
            execution.input_file(params.get("mask_image", None))
        ])
    if params.get("alpha", None) is not None:
        cargs.extend([
            "-a",
            str(params.get("alpha", None))
        ])
    if params.get("functional_overlay", None) is not None:
        cargs.extend([
            "-e",
            params.get("functional_overlay", None)
        ])
    cargs.extend([
        "-o",
        params.get("output", None)
    ])
    if params.get("tile_geometry", None) is not None:
        cargs.extend([
            "-t",
            params.get("tile_geometry", None)
        ])
    if params.get("direction", None) is not None:
        cargs.extend([
            "-d",
            params.get("direction", None)
        ])
    if params.get("pad_or_crop", None) is not None:
        cargs.extend([
            "-p",
            params.get("pad_or_crop", None)
        ])
    if params.get("slices", None) is not None:
        cargs.extend([
            "-s",
            params.get("slices", None)
        ])
    if params.get("flip_slice", None) is not None:
        cargs.extend([
            "-f",
            params.get("flip_slice", None)
        ])
    if params.get("permute_axes", None) is not None:
        cargs.extend([
            "-g",
            ("1" if params.get("permute_axes", None) else "0")
        ])
    return cargs


def create_tiled_mosaic_outputs(
    params: CreateTiledMosaicParamsDict,
    execution: Execution,
) -> CreateTiledMosaicOutputs:
    """
    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 = CreateTiledMosaicOutputs(
        root=execution.output_file("."),
        tiled_mosaic_image=execution.output_file(params.get("output", None)),
    )
    return ret


def create_tiled_mosaic_execute(
    params: CreateTiledMosaicParamsDict,
    runner: Runner | None = None,
) -> CreateTiledMosaicOutputs:
    """
    CreateTiledMosaic
    
    Render a 3-D image volume with optional Rgb overlay.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CreateTiledMosaicOutputs`).
    """
    create_tiled_mosaic_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CREATE_TILED_MOSAIC_METADATA)
    params = execution.params(params)
    cargs = create_tiled_mosaic_cargs(params, execution)
    ret = create_tiled_mosaic_outputs(params, execution)
    execution.run(cargs)
    return ret


def create_tiled_mosaic(
    input_image: InputPathType,
    output: str,
    rgb_image: InputPathType | None = None,
    mask_image: InputPathType | None = None,
    alpha: float | None = None,
    functional_overlay: str | None = None,
    tile_geometry: str | None = None,
    direction: typing.Literal["0", "1", "2", "x", "y", "z"] | None = None,
    pad_or_crop: str | None = None,
    slices: str | None = None,
    flip_slice: str | None = None,
    permute_axes: bool | None = None,
    runner: Runner | None = None,
) -> CreateTiledMosaicOutputs:
    """
    CreateTiledMosaic
    
    Render a 3-D image volume with optional Rgb overlay.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        input_image: Main input is a 3-D grayscale image.
        output: The output is the tiled mosaic image. The format must support\
            the specific data type: floating point images without RGB overlays, Rgb\
            images with intensities scaled to [0,255] if overlays are present.
        rgb_image: An optional Rgb image can be added as an overlay. It must\
            have the same image geometry as the input grayscale image.
        mask_image: Specifies the ROI of the RGB voxels used.
        alpha: If an Rgb image is provided, render the overlay using the\
            specified alpha parameter.
        functional_overlay: A functional overlay can be specified using both\
            and rgb image and a mask specifying where that rgb image should be\
            applied. Both images must have the same image geometry as the input\
            image. Optionally, an alpha parameter can be specified.
        tile_geometry: The tile geometry specifies the number of rows and\
            columns in the output image. For example, specifying '5x10' renders 5\
            rows by 10 columns of slices.
        direction: Specifies the direction of the slices. Can be based on image\
            storage in memory or aligned physical space. Defaults to z-direction if\
            unspecified.
        pad_or_crop: Specify padding or cropping with a voxel-width boundary\
            for each slice. Padding uses a specified constant value. Cropping pads\
            with negative voxel-widths.
        slices: Control over which slices to render. Specify slices directly or\
            incrementally with optional start and end slices.
        flip_slice: Flip individual slice images horizontally and/or\
            vertically.
        permute_axes: Permute (or swap) the axes of the individual slice\
            images.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CreateTiledMosaicOutputs`).
    """
    params = create_tiled_mosaic_params(
        input_image=input_image,
        rgb_image=rgb_image,
        mask_image=mask_image,
        alpha=alpha,
        functional_overlay=functional_overlay,
        output=output,
        tile_geometry=tile_geometry,
        direction=direction,
        pad_or_crop=pad_or_crop,
        slices=slices,
        flip_slice=flip_slice,
        permute_axes=permute_axes,
    )
    return create_tiled_mosaic_execute(params, runner)


__all__ = [
    "CREATE_TILED_MOSAIC_METADATA",
    "CreateTiledMosaicOutputs",
    "CreateTiledMosaicParamsDict",
    "CreateTiledMosaicParamsDictTagged",
    "create_tiled_mosaic",
    "create_tiled_mosaic_execute",
    "create_tiled_mosaic_params",
]
