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

import typing
import pathlib
from styxdefs import *
import dataclasses

V__ROI_MODAL_GROW_METADATA = Metadata(
    id="d33815ad6bfc8ff7ac694bacf23eb5bed10577bf.boutiques",
    name="@ROI_modal_grow",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class VRoiModalGrowOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v__roi_modal_grow(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType | None
    """Final output dataset"""


def v__roi_modal_grow(
    input_dset: InputPathType,
    niters: float,
    outdir: str | None = None,
    mask: InputPathType | None = None,
    prefix: str | None = None,
    neighborhood_type: int | None = None,
    runner: Runner | None = None,
) -> VRoiModalGrowOutputs:
    """
    Script to grow a set of regions in a volumetric dataset using modal smoothing.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        input_dset: Required input dataset. This dataset should be a set of\
            integer values, assuming approximate isotropic voxels.
        niters: Number of iterations for modal growth, generally making sense\
            for values from about 1-10.
        outdir: Directory name for output. All output goes to this directory.\
            Default is rmgrow.
        mask: Mask dataset at the same grid as the input dataset. Could be a\
            dilated version of the original mask or a larger region like a cortical\
            ribbon mask. Not required but often desirable.
        prefix: Base name of the final output dataset, i.e., baseprefix.nii.gz.\
            Default is rmg, so output would be rmg.nii.gz.
        neighborhood_type: Neighborhood type used in finding mode. 1 - facing\
            neighbors, 2 - edges, 3 - corners.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VRoiModalGrowOutputs`).
    """
    if neighborhood_type is not None and not (1 <= neighborhood_type <= 3): 
        raise ValueError(f"'neighborhood_type' must be between 1 <= x <= 3 but was {neighborhood_type}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(V__ROI_MODAL_GROW_METADATA)
    cargs = []
    cargs.append("@ROI_modal_grow")
    cargs.extend([
        "-input",
        execution.input_file(input_dset)
    ])
    cargs.extend([
        "-niters",
        str(niters)
    ])
    if outdir is not None:
        cargs.extend([
            "-outdir",
            outdir
        ])
    if mask is not None:
        cargs.extend([
            "-mask",
            execution.input_file(mask)
        ])
    if prefix is not None:
        cargs.extend([
            "-prefix",
            prefix
        ])
    if neighborhood_type is not None:
        cargs.extend([
            "-NN",
            str(neighborhood_type)
        ])
    ret = VRoiModalGrowOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file(outdir + "/" + prefix + ".nii.gz") if (outdir is not None and prefix is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "VRoiModalGrowOutputs",
    "V__ROI_MODAL_GROW_METADATA",
    "v__roi_modal_grow",
]
