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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_2DCAT_METADATA = Metadata(
    id="86c841e523ad32a9e63fcb9b28fa7555580ced48.boutiques",
    name="2dcat",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V2dcatOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_2dcat(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_image: OutputPathType | None
    """The main output image matrix file."""
    output_1_d: OutputPathType | None
    """A 1D file containing the average of RGB values, if the prefix ends with
    .1D."""


def v_2dcat(
    filenames: list[InputPathType],
    scale_image: InputPathType | None = None,
    scale_pixels: InputPathType | None = None,
    scale_intensity: bool = False,
    gscale: float | None = None,
    rgb_out: bool = False,
    res_in: list[float] | None = None,
    respad_in: list[float] | None = None,
    pad_val: float | None = None,
    crop: list[float] | None = None,
    autocrop_ctol: float | None = None,
    autocrop_atol: float | None = None,
    autocrop: bool = False,
    zero_wrap: bool = False,
    white_wrap: bool = False,
    gray_wrap: float | None = None,
    image_wrap: bool = False,
    rand_wrap: bool = False,
    prefix: str | None = None,
    matrix: list[float] | None = None,
    nx: float | None = None,
    ny: float | None = None,
    matrix_from_scale: bool = False,
    gap: float | None = None,
    gap_col: list[float] | None = None,
    runner: Runner | None = None,
) -> V2dcatOutputs:
    """
    Puts a set of images into an image matrix montage of NX by NY images.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        filenames: List of input image files.
        scale_image: Multiply each image in the output image matrix by the\
            color or intensity of the pixel in the scale image.
        scale_pixels: Multiply each pixel in the output image by the color or\
            intensity of the pixel in the scale image. The scale image is resized\
            to the output image's resolution.
        scale_intensity: Use the intensity (average color) of the pixel instead\
            of its color.
        gscale: Apply additional scaling factor.
        rgb_out: Force output to be in RGB, even if input is bytes.
        res_in: Set resolution of all input images.
        respad_in: Resample to max while respecting the aspect ratio, then pad\
            to desired pixel count.
        pad_val: Set the padding value when using -respad_in. Should be in the\
            range [0, 255], default is 0.
        crop: Crop images by specified number of pixels from the left, right,\
            top, and bottom.
        autocrop_ctol: Automatically crop lines where RGB values differ by less\
            than the specified percentage from the corner pixel values.
        autocrop_atol: Automatically crop lines where RGB values differ by less\
            than the specified percentage from the line average.
        autocrop: Automatically crop lines with default tolerances using both\
            autocrop_atol and autocrop_ctol set to 20.
        zero_wrap: Use solid black images if not enough images are provided to\
            fill the matrix.
        white_wrap: Use solid white images if not enough images are provided to\
            fill the matrix.
        gray_wrap: Use solid gray images if not enough images are provided to\
            fill the matrix. The gray value must be between 0 and 1.0.
        image_wrap: Reuse images to fill the matrix. This is the default\
            behavior.
        rand_wrap: Randomize the order of images when reusing to fill the\
            matrix.
        prefix: Prefix the output file names with the specified string.
        matrix: Specify the number of images in each row (NX) and column (NY)\
            of the image matrix.
        nx: Specify the number of images in each row.
        ny: Specify the number of images in each column.
        matrix_from_scale: Set matrix dimensions NX and NY to be the same as\
            the SCALE_IMG's dimensions. Requires the -scale_image option.
        gap: Put a gap of specified pixels between images.
        gap_col: Set color of the gap line to specified R, G, B values. Values\
            range from 0 to 255.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V2dcatOutputs`).
    """
    if pad_val is not None and not (0 <= pad_val <= 255): 
        raise ValueError(f"'pad_val' must be between 0 <= x <= 255 but was {pad_val}")
    if gray_wrap is not None and not (0 <= gray_wrap <= 1): 
        raise ValueError(f"'gray_wrap' must be between 0 <= x <= 1 but was {gray_wrap}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_2DCAT_METADATA)
    cargs = []
    cargs.append("2dcat")
    cargs.extend([execution.input_file(f) for f in filenames])
    if scale_image is not None:
        cargs.extend([
            "-scale_image",
            execution.input_file(scale_image)
        ])
    if scale_pixels is not None:
        cargs.extend([
            "-scale_pixels",
            execution.input_file(scale_pixels)
        ])
    if scale_intensity:
        cargs.append("-scale_intensity")
    if gscale is not None:
        cargs.extend([
            "-gscale",
            str(gscale)
        ])
    if rgb_out:
        cargs.append("-rgb_out")
    if res_in is not None:
        cargs.extend([
            "-res_in",
            *map(str, res_in)
        ])
    if respad_in is not None:
        cargs.extend([
            "-respad_in",
            *map(str, respad_in)
        ])
    if pad_val is not None:
        cargs.extend([
            "-pad_val",
            str(pad_val)
        ])
    if crop is not None:
        cargs.extend([
            "-crop",
            *map(str, crop)
        ])
    if autocrop_ctol is not None:
        cargs.extend([
            "-autocrop_ctol",
            str(autocrop_ctol)
        ])
    if autocrop_atol is not None:
        cargs.extend([
            "-autocrop_atol",
            str(autocrop_atol)
        ])
    if autocrop:
        cargs.append("-autocrop")
    if zero_wrap:
        cargs.append("-zero_wrap")
    if white_wrap:
        cargs.append("-white_wrap")
    if gray_wrap is not None:
        cargs.extend([
            "-gray_wrap",
            str(gray_wrap)
        ])
    if image_wrap:
        cargs.append("-image_wrap")
    if rand_wrap:
        cargs.append("-rand_wrap")
    if prefix is not None:
        cargs.extend([
            "-prefix",
            prefix
        ])
    if matrix is not None:
        cargs.extend([
            "-matrix",
            *map(str, matrix)
        ])
    if nx is not None:
        cargs.extend([
            "-nx",
            str(nx)
        ])
    if ny is not None:
        cargs.extend([
            "-ny",
            str(ny)
        ])
    if matrix_from_scale:
        cargs.append("-matrix_from_scale")
    if gap is not None:
        cargs.extend([
            "-gap",
            str(gap)
        ])
    if gap_col is not None:
        cargs.extend([
            "-gap_col",
            *map(str, gap_col)
        ])
    ret = V2dcatOutputs(
        root=execution.output_file("."),
        output_image=execution.output_file(prefix + ".ppm") if (prefix is not None) else None,
        output_1_d=execution.output_file(prefix + ".1D") if (prefix is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V2dcatOutputs",
    "V_2DCAT_METADATA",
    "v_2dcat",
]
