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

import typing
import pathlib
from styxdefs import *

VOLUME_ESTIMATE_FWHM_METADATA = Metadata(
    id="25607ae5dff68c55973abc5a13016a50bb089e8e.workbench",
    name="volume-estimate-fwhm",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_VolumeEstimateFwhmParamsDictNoTag = typing.TypedDict('_VolumeEstimateFwhmParamsDictNoTag', {
    "volume": InputPathType,
    "demean": typing.NotRequired[bool | None],
    "subvol": typing.NotRequired[str | None],
    "roivol": typing.NotRequired[InputPathType | None],
})
VolumeEstimateFwhmParamsDictTagged = typing.TypedDict('VolumeEstimateFwhmParamsDictTagged', {
    "@type": typing.Literal["workbench/volume-estimate-fwhm"],
    "volume": InputPathType,
    "demean": typing.NotRequired[bool | None],
    "subvol": typing.NotRequired[str | None],
    "roivol": typing.NotRequired[InputPathType | None],
})
VolumeEstimateFwhmParamsDict = _VolumeEstimateFwhmParamsDictNoTag | VolumeEstimateFwhmParamsDictTagged


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


def volume_estimate_fwhm_params(
    volume: InputPathType,
    demean: bool | None = None,
    subvol: str | None = None,
    roivol: InputPathType | None = None,
) -> VolumeEstimateFwhmParamsDictTagged:
    """
    Build parameters.
    
    Args:
        volume: the input volume.
        demean: estimate for the whole file at once, not each subvolume\
            separately\
            \
            subtract the mean image before estimating smoothness.
        subvol: select a single subvolume to estimate smoothness of\
            \
            the subvolume number or name.
        roivol: use only data within an ROI\
            \
            the volume to use as an ROI.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/volume-estimate-fwhm",
        "volume": volume,
    }
    if demean is not None:
        params["demean"] = demean
    if subvol is not None:
        params["subvol"] = subvol
    if roivol is not None:
        params["roivol"] = roivol
    return params


def volume_estimate_fwhm_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `VolumeEstimateFwhmParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("volume", None) is None:
        raise StyxValidationError("`volume` must not be None")
    if not isinstance(params["volume"], (pathlib.Path, str)):
        raise StyxValidationError(f'`volume` has the wrong type: Received `{type(params.get("volume", None))}` expected `InputPathType`')
    if params.get("demean", None) is not None:
        if not isinstance(params["demean"], bool):
            raise StyxValidationError(f'`demean` has the wrong type: Received `{type(params.get("demean", None))}` expected `bool | None`')
    if params.get("subvol", None) is not None:
        if not isinstance(params["subvol"], str):
            raise StyxValidationError(f'`subvol` has the wrong type: Received `{type(params.get("subvol", None))}` expected `str | None`')
    if params.get("roivol", None) is not None:
        if not isinstance(params["roivol"], (pathlib.Path, str)):
            raise StyxValidationError(f'`roivol` has the wrong type: Received `{type(params.get("roivol", None))}` expected `InputPathType | None`')


def volume_estimate_fwhm_cargs(
    params: VolumeEstimateFwhmParamsDict,
    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.extend([
        "wb_command",
        "-volume-estimate-fwhm"
    ])
    cargs.append(execution.input_file(params.get("volume", None)))
    if params.get("demean", None) is not None:
        cargs.extend([
            "-whole-file",
            "-demean"
        ])
    if params.get("subvol", None) is not None:
        cargs.extend([
            "-subvolume",
            params.get("subvol", None)
        ])
    if params.get("roivol", None) is not None:
        cargs.extend([
            "-roi",
            execution.input_file(params.get("roivol", None))
        ])
    return cargs


def volume_estimate_fwhm_outputs(
    params: VolumeEstimateFwhmParamsDict,
    execution: Execution,
) -> VolumeEstimateFwhmOutputs:
    """
    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 = VolumeEstimateFwhmOutputs(
        root=execution.output_file("."),
    )
    return ret


def volume_estimate_fwhm_execute(
    params: VolumeEstimateFwhmParamsDict,
    runner: Runner | None = None,
) -> VolumeEstimateFwhmOutputs:
    """
    ESTIMATE FWHM SMOOTHNESS OF A VOLUME.
    
    Estimates the smoothness of the input volume in X, Y, and Z directions
    separately, printing the estimates to standard output, in mm as FWHM. If
    -subvolume or -whole-file are not specified, each subvolume is estimated and
    displayed separately.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeEstimateFwhmOutputs`).
    """
    volume_estimate_fwhm_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_ESTIMATE_FWHM_METADATA)
    params = execution.params(params)
    cargs = volume_estimate_fwhm_cargs(params, execution)
    ret = volume_estimate_fwhm_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_estimate_fwhm(
    volume: InputPathType,
    demean: bool | None = None,
    subvol: str | None = None,
    roivol: InputPathType | None = None,
    runner: Runner | None = None,
) -> VolumeEstimateFwhmOutputs:
    """
    ESTIMATE FWHM SMOOTHNESS OF A VOLUME.
    
    Estimates the smoothness of the input volume in X, Y, and Z directions
    separately, printing the estimates to standard output, in mm as FWHM. If
    -subvolume or -whole-file are not specified, each subvolume is estimated and
    displayed separately.
    
    Args:
        volume: the input volume.
        demean: estimate for the whole file at once, not each subvolume\
            separately\
            \
            subtract the mean image before estimating smoothness.
        subvol: select a single subvolume to estimate smoothness of\
            \
            the subvolume number or name.
        roivol: use only data within an ROI\
            \
            the volume to use as an ROI.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeEstimateFwhmOutputs`).
    """
    params = volume_estimate_fwhm_params(
        volume=volume,
        demean=demean,
        subvol=subvol,
        roivol=roivol,
    )
    return volume_estimate_fwhm_execute(params, runner)


__all__ = [
    "VOLUME_ESTIMATE_FWHM_METADATA",
    "VolumeEstimateFwhmOutputs",
    "VolumeEstimateFwhmParamsDict",
    "VolumeEstimateFwhmParamsDictTagged",
    "volume_estimate_fwhm",
    "volume_estimate_fwhm_execute",
    "volume_estimate_fwhm_params",
]
