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

import typing
import pathlib
from styxdefs import *
import dataclasses

VOLUME_STATS_METADATA = Metadata(
    id="18763776102c87c9e4124a22b788fb040dbe949b.boutiques",
    name="volume-stats",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


@dataclasses.dataclass
class VolumeStatsRoi:
    """
    only consider data inside an roi.
    """
    roi_volume: InputPathType
    """the roi, as a volume file"""
    opt_match_maps: bool = False
    """each subvolume of input uses the corresponding subvolume from the roi
    file"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-roi")
        cargs.append(execution.input_file(self.roi_volume))
        if self.opt_match_maps:
            cargs.append("-match-maps")
        return cargs


class VolumeStatsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `volume_stats(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def volume_stats(
    volume_in: InputPathType,
    opt_reduce_operation: str | None = None,
    opt_percentile_percent: float | None = None,
    opt_subvolume_subvolume: str | None = None,
    roi: VolumeStatsRoi | None = None,
    opt_show_map_name: bool = False,
    runner: Runner | None = None,
) -> VolumeStatsOutputs:
    """
    Spatial statistics on a volume file.
    
    For each subvolume of the input, a line of text is printed, resulting from
    the specified reduction or percentile operation. Use -subvolume to only give
    output for a single subvolume. If the -roi option is used without
    -match-maps, then each line will contain as many numbers as there are maps
    in the ROI file, separated by tab characters. Exactly one of -reduce or
    -percentile must be specified.
    
    The argument to the -reduce option must be one of the following:
    
    MAX: the maximum value
    MIN: the minimum value
    INDEXMAX: the 1-based index of the maximum value
    INDEXMIN: the 1-based index of the minimum value
    SUM: add all values
    PRODUCT: multiply all values
    MEAN: the mean of the data
    STDEV: the standard deviation (N denominator)
    SAMPSTDEV: the sample standard deviation (N-1 denominator)
    VARIANCE: the variance of the data
    TSNR: mean divided by sample standard deviation (N-1 denominator)
    COV: sample standard deviation (N-1 denominator) divided by mean
    L2NORM: square root of sum of squares
    MEDIAN: the median of the data
    MODE: the mode of the data
    COUNT_NONZERO: the number of nonzero elements in the data
    .
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        volume_in: the input volume.
        opt_reduce_operation: use a reduction operation: the reduction\
            operation.
        opt_percentile_percent: give the value at a percentile: the percentile\
            to find, must be between 0 and 100.
        opt_subvolume_subvolume: only display output for one subvolume: the\
            subvolume number or name.
        roi: only consider data inside an roi.
        opt_show_map_name: print map index and name before each output.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeStatsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_STATS_METADATA)
    cargs = []
    cargs.append("wb_command")
    cargs.append("-volume-stats")
    cargs.append(execution.input_file(volume_in))
    if opt_reduce_operation is not None:
        cargs.extend([
            "-reduce",
            opt_reduce_operation
        ])
    if opt_percentile_percent is not None:
        cargs.extend([
            "-percentile",
            str(opt_percentile_percent)
        ])
    if opt_subvolume_subvolume is not None:
        cargs.extend([
            "-subvolume",
            opt_subvolume_subvolume
        ])
    if roi is not None:
        cargs.extend(roi.run(execution))
    if opt_show_map_name:
        cargs.append("-show-map-name")
    ret = VolumeStatsOutputs(
        root=execution.output_file("."),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "VOLUME_STATS_METADATA",
    "VolumeStatsOutputs",
    "VolumeStatsRoi",
    "volume_stats",
]
