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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRSTATS_METADATA = Metadata(
    id="d6b6130eadba4cd34c792009b27a777f19edbda6.boutiques",
    name="mrstats",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


@dataclasses.dataclass
class MrstatsOutput:
    """
    output only the field specified. Multiple such options can be supplied if
    required. Choices are: mean, median, std, std_rv, min, max, count. Useful
    for use in scripts. Both std options refer to the unbiased (sample) standard
    deviation. For complex data, min, max and std are calculated separately for
    real and imaginary parts, std_rv is based on the real valued variance
    (equals sqrt of sum of variances of imaginary and real parts).
    """
    field: str
    """output only the field specified. Multiple such options can be supplied if
    required. Choices are: mean, median, std, std_rv, min, max, count. Useful
    for use in scripts. Both std options refer to the unbiased (sample) standard
    deviation. For complex data, min, max and std are calculated separately for
    real and imaginary parts, std_rv is based on the real valued variance
    (equals sqrt of sum of variances of imaginary and real parts)."""
    
    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("-output")
        cargs.append(self.field)
        return cargs


@dataclasses.dataclass
class MrstatsConfig:
    """
    temporarily set the value of an MRtrix config file entry.
    """
    key: str
    """temporarily set the value of an MRtrix config file entry."""
    value: str
    """temporarily set the value of an MRtrix config file entry."""
    
    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("-config")
        cargs.append(self.key)
        cargs.append(self.value)
        return cargs


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


def mrstats(
    image: InputPathType,
    output: list[MrstatsOutput] | None = None,
    mask: InputPathType | None = None,
    ignorezero: bool = False,
    allvolumes: bool = False,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrstatsConfig] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> MrstatsOutputs:
    """
    Compute images statistics.
    
    
    
    References:
    
    .
    
    Author: J-Donald Tournier (jdtournier@gmail.com)
    
    URL: https://mrtrix.readthedocs.io/en/latest/reference/commands/mrstats.html
    
    Args:
        image: the input image from which statistics will be computed.
        output: output only the field specified. Multiple such options can be\
            supplied if required. Choices are: mean, median, std, std_rv, min, max,\
            count. Useful for use in scripts. Both std options refer to the\
            unbiased (sample) standard deviation. For complex data, min, max and\
            std are calculated separately for real and imaginary parts, std_rv is\
            based on the real valued variance (equals sqrt of sum of variances of\
            imaginary and real parts).
        mask: only perform computation within the specified binary mask image.
        ignorezero: ignore zero values during statistics calculation.
        allvolumes: generate statistics across all image volumes, rather than\
            one set of statistics per image volume.
        info: display information messages.
        quiet: do not display information messages or progress status;\
            alternatively, this can be achieved by setting the MRTRIX_QUIET\
            environment variable to a non-empty string.
        debug: display debugging messages.
        force: force overwrite of output files (caution: using the same file as\
            input and output might cause unexpected behaviour).
        nthreads: use this number of threads in multi-threaded applications\
            (set to 0 to disable multi-threading).
        config: temporarily set the value of an MRtrix config file entry.
        help_: display this information page and exit.
        version: display version information and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MrstatsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRSTATS_METADATA)
    cargs = []
    cargs.append("mrstats")
    if output is not None:
        cargs.extend([a for c in [s.run(execution) for s in output] for a in c])
    if mask is not None:
        cargs.extend([
            "-mask",
            execution.input_file(mask)
        ])
    if ignorezero:
        cargs.append("-ignorezero")
    if allvolumes:
        cargs.append("-allvolumes")
    if info:
        cargs.append("-info")
    if quiet:
        cargs.append("-quiet")
    if debug:
        cargs.append("-debug")
    if force:
        cargs.append("-force")
    if nthreads is not None:
        cargs.extend([
            "-nthreads",
            str(nthreads)
        ])
    if config is not None:
        cargs.extend([a for c in [s.run(execution) for s in config] for a in c])
    if help_:
        cargs.append("-help")
    if version:
        cargs.append("-version")
    cargs.append(execution.input_file(image))
    ret = MrstatsOutputs(
        root=execution.output_file("."),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRSTATS_METADATA",
    "MrstatsConfig",
    "MrstatsOutput",
    "MrstatsOutputs",
    "mrstats",
]
