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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_3D_LOCALSTAT_METADATA = Metadata(
    id="f927c9d4ad8b0ef0fa566fe0b9648789d0b3eb44.boutiques",
    name="3dLocalstat",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V3dLocalstatOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_3d_localstat(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    outfile: OutputPathType | None
    """Output dataset"""


def v_3d_localstat(
    dataset: InputPathType,
    nbhd: str,
    stat_: list[str] | None = None,
    mask: InputPathType | None = None,
    automask: bool = False,
    use_nonmask: bool = False,
    prefix: str | None = None,
    datum: str | None = None,
    label_ext: str | None = None,
    reduce_grid: list[float] | None = None,
    reduce_restore_grid: list[float] | None = None,
    reduce_max_vox: float | None = None,
    grid_rmode: str | None = None,
    quiet: bool = False,
    verbose: bool = False,
    proceed_small_n: bool = False,
    fillvalue: float | None = None,
    unfillvalue: float | None = None,
    maskvalue: float | None = None,
    maskvalue2: float | None = None,
    runner: Runner | None = None,
) -> V3dLocalstatOutputs:
    """
    This program computes statistics at each voxel, based on a local neighborhood of
    that voxel.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        dataset: Input dataset.
        nbhd: The region around each voxel that will be extracted for the\
            statistics calculation.
        stat_: Compute the specified statistic on the values extracted from the\
            neighborhood.
        mask: Read in dataset 'mset' and use the nonzero voxels therein as a\
            mask.
        automask: Compute the mask as in program 3dAutomask (mutually exclusive\
            with -mask).
        use_nonmask: Compute local statistics from all voxels in the\
            neighborhood that are in the mask, even if the central voxel is not in\
            the mask.
        prefix: Use the given string as the prefix for the output dataset.
        datum: Coerce the output data to be stored as the given type (byte,\
            short, float).
        label_ext: Append given label to each sub-brick label.
        reduce_grid: Compute output on a grid that is reduced by the given\
            factor in X, Y, and Z directions of the input dataset.
        reduce_restore_grid: Resample the output back to input grid after\
            reducing the grid.
        reduce_max_vox: Automatically set Rx Ry Rz so that the computation grid\
            is at a resolution of nbhd/MAX_VOX voxels.
        grid_rmode: Interpolant to use when resampling the output with\
            reduce_restore_grid option.
        quiet: Stop the highly informative progress reports.
        verbose: A little more verbose output.
        proceed_small_n: Do not crash if neighborhood is too small for certain\
            estimates.
        fillvalue: Value used for filled statistic, default=1.
        unfillvalue: Value used for unfilled statistic, default=1.
        maskvalue: Value searched for with has_mask option.
        maskvalue2: Alternate value for has_mask2 option.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V3dLocalstatOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_3D_LOCALSTAT_METADATA)
    cargs = []
    cargs.append("3dLocalstat")
    cargs.append(execution.input_file(dataset))
    cargs.extend([
        "-nbhd",
        nbhd
    ])
    if stat_ is not None:
        cargs.extend([
            "-stat",
            *stat_
        ])
    if mask is not None:
        cargs.extend([
            "-mask",
            execution.input_file(mask)
        ])
    if automask:
        cargs.append("-automask")
    if use_nonmask:
        cargs.append("-use_nonmask")
    if prefix is not None:
        cargs.extend([
            "-prefix",
            prefix
        ])
    if datum is not None:
        cargs.extend([
            "-datum",
            datum
        ])
    if label_ext is not None:
        cargs.extend([
            "-label_ext",
            label_ext
        ])
    if reduce_grid is not None:
        cargs.extend([
            "-reduce_grid",
            *map(str, reduce_grid)
        ])
    if reduce_restore_grid is not None:
        cargs.extend([
            "-reduce_restore_grid",
            *map(str, reduce_restore_grid)
        ])
    if reduce_max_vox is not None:
        cargs.extend([
            "-reduce_max_vox",
            str(reduce_max_vox)
        ])
    if grid_rmode is not None:
        cargs.extend([
            "-grid_rmode",
            grid_rmode
        ])
    if quiet:
        cargs.append("-quiet")
    if verbose:
        cargs.append("-verb")
    if proceed_small_n:
        cargs.append("-proceed_small_N")
    if fillvalue is not None:
        cargs.extend([
            "-fillvalue",
            str(fillvalue)
        ])
    if unfillvalue is not None:
        cargs.extend([
            "-unfillvalue",
            str(unfillvalue)
        ])
    if maskvalue is not None:
        cargs.extend([
            "-maskvalue",
            str(maskvalue)
        ])
    if maskvalue2 is not None:
        cargs.extend([
            "-maskvalue2",
            str(maskvalue2)
        ])
    ret = V3dLocalstatOutputs(
        root=execution.output_file("."),
        outfile=execution.output_file(prefix + ".nii.gz") if (prefix is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V3dLocalstatOutputs",
    "V_3D_LOCALSTAT_METADATA",
    "v_3d_localstat",
]
