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

import typing
import pathlib
from styxdefs import *

VOLUME_WEIGHTED_STATS_METADATA = Metadata(
    id="cc98b5f18ee1944d35c3bdc722bfbd19a6850252.boutiques",
    name="volume-weighted-stats",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


VolumeWeightedStatsWeightVolumeParameters = typing.TypedDict('VolumeWeightedStatsWeightVolumeParameters', {
    "@type": typing.NotRequired[typing.Literal["weight_volume"]],
    "weight_volume": InputPathType,
    "opt_match_maps": bool,
})
VolumeWeightedStatsWeightVolumeParametersTagged = typing.TypedDict('VolumeWeightedStatsWeightVolumeParametersTagged', {
    "@type": typing.Literal["weight_volume"],
    "weight_volume": InputPathType,
    "opt_match_maps": bool,
})


VolumeWeightedStatsRoiParameters = typing.TypedDict('VolumeWeightedStatsRoiParameters', {
    "@type": typing.NotRequired[typing.Literal["roi"]],
    "roi_volume": InputPathType,
    "opt_match_maps": bool,
})
VolumeWeightedStatsRoiParametersTagged = typing.TypedDict('VolumeWeightedStatsRoiParametersTagged', {
    "@type": typing.Literal["roi"],
    "roi_volume": InputPathType,
    "opt_match_maps": bool,
})


VolumeWeightedStatsStdevParameters = typing.TypedDict('VolumeWeightedStatsStdevParameters', {
    "@type": typing.NotRequired[typing.Literal["stdev"]],
    "opt_sample": bool,
})
VolumeWeightedStatsStdevParametersTagged = typing.TypedDict('VolumeWeightedStatsStdevParametersTagged', {
    "@type": typing.Literal["stdev"],
    "opt_sample": bool,
})


VolumeWeightedStatsParameters = typing.TypedDict('VolumeWeightedStatsParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/volume-weighted-stats"]],
    "volume_in": InputPathType,
    "weight_volume": typing.NotRequired[VolumeWeightedStatsWeightVolumeParameters | None],
    "opt_subvolume_subvolume": typing.NotRequired[str | None],
    "roi": typing.NotRequired[VolumeWeightedStatsRoiParameters | None],
    "opt_mean": bool,
    "stdev": typing.NotRequired[VolumeWeightedStatsStdevParameters | None],
    "opt_percentile_percent": typing.NotRequired[float | None],
    "opt_sum": bool,
    "opt_show_map_name": bool,
})
VolumeWeightedStatsParametersTagged = typing.TypedDict('VolumeWeightedStatsParametersTagged', {
    "@type": typing.Literal["workbench/volume-weighted-stats"],
    "volume_in": InputPathType,
    "weight_volume": typing.NotRequired[VolumeWeightedStatsWeightVolumeParameters | None],
    "opt_subvolume_subvolume": typing.NotRequired[str | None],
    "roi": typing.NotRequired[VolumeWeightedStatsRoiParameters | None],
    "opt_mean": bool,
    "stdev": typing.NotRequired[VolumeWeightedStatsStdevParameters | None],
    "opt_percentile_percent": typing.NotRequired[float | None],
    "opt_sum": bool,
    "opt_show_map_name": bool,
})


def volume_weighted_stats_weight_volume_params(
    weight_volume: InputPathType,
    opt_match_maps: bool = False,
) -> VolumeWeightedStatsWeightVolumeParametersTagged:
    """
    Build parameters.
    
    Args:
        weight_volume: volume file containing the weights.
        opt_match_maps: each subvolume of input uses the corresponding\
            subvolume from the weights file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "weight_volume",
        "weight_volume": weight_volume,
        "opt_match_maps": opt_match_maps,
    }
    return params


def volume_weighted_stats_weight_volume_cargs(
    params: VolumeWeightedStatsWeightVolumeParameters,
    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("-weight-volume")
    cargs.append(execution.input_file(params.get("weight_volume", None)))
    if params.get("opt_match_maps", False):
        cargs.append("-match-maps")
    return cargs


def volume_weighted_stats_roi_params(
    roi_volume: InputPathType,
    opt_match_maps: bool = False,
) -> VolumeWeightedStatsRoiParametersTagged:
    """
    Build parameters.
    
    Args:
        roi_volume: the roi, as a volume file.
        opt_match_maps: each subvolume of input uses the corresponding\
            subvolume from the roi file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "roi",
        "roi_volume": roi_volume,
        "opt_match_maps": opt_match_maps,
    }
    return params


def volume_weighted_stats_roi_cargs(
    params: VolumeWeightedStatsRoiParameters,
    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("-roi")
    cargs.append(execution.input_file(params.get("roi_volume", None)))
    if params.get("opt_match_maps", False):
        cargs.append("-match-maps")
    return cargs


def volume_weighted_stats_stdev_params(
    opt_sample: bool = False,
) -> VolumeWeightedStatsStdevParametersTagged:
    """
    Build parameters.
    
    Args:
        opt_sample: estimate population stdev from the sample.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "stdev",
        "opt_sample": opt_sample,
    }
    return params


def volume_weighted_stats_stdev_cargs(
    params: VolumeWeightedStatsStdevParameters,
    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("-stdev")
    if params.get("opt_sample", False):
        cargs.append("-sample")
    return cargs


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


def volume_weighted_stats_params(
    volume_in: InputPathType,
    weight_volume: VolumeWeightedStatsWeightVolumeParameters | None = None,
    opt_subvolume_subvolume: str | None = None,
    roi: VolumeWeightedStatsRoiParameters | None = None,
    opt_mean: bool = False,
    stdev: VolumeWeightedStatsStdevParameters | None = None,
    opt_percentile_percent: float | None = None,
    opt_sum: bool = False,
    opt_show_map_name: bool = False,
) -> VolumeWeightedStatsParametersTagged:
    """
    Build parameters.
    
    Args:
        volume_in: the input volume.
        weight_volume: use weights from a volume file.
        opt_subvolume_subvolume: only display output for one subvolume: the\
            subvolume number or name.
        roi: only consider data inside an roi.
        opt_mean: compute weighted mean.
        stdev: compute weighted standard deviation.
        opt_percentile_percent: compute weighted percentile: the percentile to\
            find, must be between 0 and 100.
        opt_sum: compute weighted sum.
        opt_show_map_name: print map index and name before each output.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/volume-weighted-stats",
        "volume_in": volume_in,
        "opt_mean": opt_mean,
        "opt_sum": opt_sum,
        "opt_show_map_name": opt_show_map_name,
    }
    if weight_volume is not None:
        params["weight_volume"] = weight_volume
    if opt_subvolume_subvolume is not None:
        params["opt_subvolume_subvolume"] = opt_subvolume_subvolume
    if roi is not None:
        params["roi"] = roi
    if stdev is not None:
        params["stdev"] = stdev
    if opt_percentile_percent is not None:
        params["opt_percentile_percent"] = opt_percentile_percent
    return params


def volume_weighted_stats_cargs(
    params: VolumeWeightedStatsParameters,
    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("wb_command")
    cargs.append("-volume-weighted-stats")
    cargs.append(execution.input_file(params.get("volume_in", None)))
    if params.get("weight_volume", None) is not None:
        cargs.extend(volume_weighted_stats_weight_volume_cargs(params.get("weight_volume", None), execution))
    if params.get("opt_subvolume_subvolume", None) is not None:
        cargs.extend([
            "-subvolume",
            params.get("opt_subvolume_subvolume", None)
        ])
    if params.get("roi", None) is not None:
        cargs.extend(volume_weighted_stats_roi_cargs(params.get("roi", None), execution))
    if params.get("opt_mean", False):
        cargs.append("-mean")
    if params.get("stdev", None) is not None:
        cargs.extend(volume_weighted_stats_stdev_cargs(params.get("stdev", None), execution))
    if params.get("opt_percentile_percent", None) is not None:
        cargs.extend([
            "-percentile",
            str(params.get("opt_percentile_percent", None))
        ])
    if params.get("opt_sum", False):
        cargs.append("-sum")
    if params.get("opt_show_map_name", False):
        cargs.append("-show-map-name")
    return cargs


def volume_weighted_stats_outputs(
    params: VolumeWeightedStatsParameters,
    execution: Execution,
) -> VolumeWeightedStatsOutputs:
    """
    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 = VolumeWeightedStatsOutputs(
        root=execution.output_file("."),
    )
    return ret


def volume_weighted_stats_execute(
    params: VolumeWeightedStatsParameters,
    runner: Runner | None = None,
) -> VolumeWeightedStatsOutputs:
    """
    volume-weighted-stats
    
    Weighted spatial statistics on a volume file.
    
    For each subvolume of the input, a line of text is printed, resulting from
    the specified operation. If -weight-volume is not specified, each voxel's
    volume is used. 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 -mean, -stdev, -percentile or -sum must be
    specified.
    
    Using -sum without -weight-volume is equivalent to integrating with respect
    to volume.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeWeightedStatsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_WEIGHTED_STATS_METADATA)
    params = execution.params(params)
    cargs = volume_weighted_stats_cargs(params, execution)
    ret = volume_weighted_stats_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_weighted_stats(
    volume_in: InputPathType,
    weight_volume: VolumeWeightedStatsWeightVolumeParameters | None = None,
    opt_subvolume_subvolume: str | None = None,
    roi: VolumeWeightedStatsRoiParameters | None = None,
    opt_mean: bool = False,
    stdev: VolumeWeightedStatsStdevParameters | None = None,
    opt_percentile_percent: float | None = None,
    opt_sum: bool = False,
    opt_show_map_name: bool = False,
    runner: Runner | None = None,
) -> VolumeWeightedStatsOutputs:
    """
    volume-weighted-stats
    
    Weighted spatial statistics on a volume file.
    
    For each subvolume of the input, a line of text is printed, resulting from
    the specified operation. If -weight-volume is not specified, each voxel's
    volume is used. 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 -mean, -stdev, -percentile or -sum must be
    specified.
    
    Using -sum without -weight-volume is equivalent to integrating with respect
    to volume.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        volume_in: the input volume.
        weight_volume: use weights from a volume file.
        opt_subvolume_subvolume: only display output for one subvolume: the\
            subvolume number or name.
        roi: only consider data inside an roi.
        opt_mean: compute weighted mean.
        stdev: compute weighted standard deviation.
        opt_percentile_percent: compute weighted percentile: the percentile to\
            find, must be between 0 and 100.
        opt_sum: compute weighted sum.
        opt_show_map_name: print map index and name before each output.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeWeightedStatsOutputs`).
    """
    params = volume_weighted_stats_params(
        volume_in=volume_in,
        weight_volume=weight_volume,
        opt_subvolume_subvolume=opt_subvolume_subvolume,
        roi=roi,
        opt_mean=opt_mean,
        stdev=stdev,
        opt_percentile_percent=opt_percentile_percent,
        opt_sum=opt_sum,
        opt_show_map_name=opt_show_map_name,
    )
    return volume_weighted_stats_execute(params, runner)


__all__ = [
    "VOLUME_WEIGHTED_STATS_METADATA",
    "VolumeWeightedStatsOutputs",
    "volume_weighted_stats",
    "volume_weighted_stats_execute",
    "volume_weighted_stats_params",
    "volume_weighted_stats_roi_params",
    "volume_weighted_stats_stdev_params",
    "volume_weighted_stats_weight_volume_params",
]
