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

import typing
import pathlib
from styxdefs import *

METRIC_ESTIMATE_FWHM_METADATA = Metadata(
    id="9c0ae9d2b6ef7d3111a63f811feffe7ae9dde13f.workbench",
    name="metric-estimate-fwhm",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_MetricEstimateFwhmParamsDictNoTag = typing.TypedDict('_MetricEstimateFwhmParamsDictNoTag', {
    "surface": InputPathType,
    "metric-in": InputPathType,
    "demean": typing.NotRequired[bool | None],
    "column": typing.NotRequired[str | None],
    "roi-metric": typing.NotRequired[InputPathType | None],
})
MetricEstimateFwhmParamsDictTagged = typing.TypedDict('MetricEstimateFwhmParamsDictTagged', {
    "@type": typing.Literal["workbench/metric-estimate-fwhm"],
    "surface": InputPathType,
    "metric-in": InputPathType,
    "demean": typing.NotRequired[bool | None],
    "column": typing.NotRequired[str | None],
    "roi-metric": typing.NotRequired[InputPathType | None],
})
MetricEstimateFwhmParamsDict = _MetricEstimateFwhmParamsDictNoTag | MetricEstimateFwhmParamsDictTagged


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


def metric_estimate_fwhm_params(
    surface: InputPathType,
    metric_in: InputPathType,
    demean: bool | None = None,
    column: str | None = None,
    roi_metric: InputPathType | None = None,
) -> MetricEstimateFwhmParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface: the surface to use for distance and neighbor information.
        metric_in: the input metric.
        demean: estimate for the whole file at once, not each column separately\
            \
            subtract the mean image before estimating smoothness.
        column: select a single column to estimate smoothness of\
            \
            the column number or name.
        roi_metric: use only data within an ROI\
            \
            the metric file to use as an ROI.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/metric-estimate-fwhm",
        "surface": surface,
        "metric-in": metric_in,
    }
    if demean is not None:
        params["demean"] = demean
    if column is not None:
        params["column"] = column
    if roi_metric is not None:
        params["roi-metric"] = roi_metric
    return params


def metric_estimate_fwhm_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MetricEstimateFwhmParamsDict` 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("surface", None) is None:
        raise StyxValidationError("`surface` must not be None")
    if not isinstance(params["surface"], (pathlib.Path, str)):
        raise StyxValidationError(f'`surface` has the wrong type: Received `{type(params.get("surface", None))}` expected `InputPathType`')
    if params.get("metric-in", None) is None:
        raise StyxValidationError("`metric-in` must not be None")
    if not isinstance(params["metric-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`metric-in` has the wrong type: Received `{type(params.get("metric-in", 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("column", None) is not None:
        if not isinstance(params["column"], str):
            raise StyxValidationError(f'`column` has the wrong type: Received `{type(params.get("column", None))}` expected `str | None`')
    if params.get("roi-metric", None) is not None:
        if not isinstance(params["roi-metric"], (pathlib.Path, str)):
            raise StyxValidationError(f'`roi-metric` has the wrong type: Received `{type(params.get("roi-metric", None))}` expected `InputPathType | None`')


def metric_estimate_fwhm_cargs(
    params: MetricEstimateFwhmParamsDict,
    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",
        "-metric-estimate-fwhm"
    ])
    cargs.append(execution.input_file(params.get("surface", None)))
    cargs.append(execution.input_file(params.get("metric-in", None)))
    if params.get("demean", None) is not None:
        cargs.extend([
            "-whole-file",
            "-demean"
        ])
    if params.get("column", None) is not None:
        cargs.extend([
            "-column",
            params.get("column", None)
        ])
    if params.get("roi-metric", None) is not None:
        cargs.extend([
            "-roi",
            execution.input_file(params.get("roi-metric", None))
        ])
    return cargs


def metric_estimate_fwhm_outputs(
    params: MetricEstimateFwhmParamsDict,
    execution: Execution,
) -> MetricEstimateFwhmOutputs:
    """
    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 = MetricEstimateFwhmOutputs(
        root=execution.output_file("."),
    )
    return ret


def metric_estimate_fwhm_execute(
    params: MetricEstimateFwhmParamsDict,
    runner: Runner | None = None,
) -> MetricEstimateFwhmOutputs:
    """
    ESTIMATE FWHM SMOOTHNESS OF A METRIC FILE.
    
    Estimates the smoothness of the metric columns, printing the estimates to
    standard output. These estimates ignore variation in vertex spacing.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricEstimateFwhmOutputs`).
    """
    metric_estimate_fwhm_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_ESTIMATE_FWHM_METADATA)
    params = execution.params(params)
    cargs = metric_estimate_fwhm_cargs(params, execution)
    ret = metric_estimate_fwhm_outputs(params, execution)
    execution.run(cargs)
    return ret


def metric_estimate_fwhm(
    surface: InputPathType,
    metric_in: InputPathType,
    demean: bool | None = None,
    column: str | None = None,
    roi_metric: InputPathType | None = None,
    runner: Runner | None = None,
) -> MetricEstimateFwhmOutputs:
    """
    ESTIMATE FWHM SMOOTHNESS OF A METRIC FILE.
    
    Estimates the smoothness of the metric columns, printing the estimates to
    standard output. These estimates ignore variation in vertex spacing.
    
    Args:
        surface: the surface to use for distance and neighbor information.
        metric_in: the input metric.
        demean: estimate for the whole file at once, not each column separately\
            \
            subtract the mean image before estimating smoothness.
        column: select a single column to estimate smoothness of\
            \
            the column number or name.
        roi_metric: use only data within an ROI\
            \
            the metric file to use as an ROI.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricEstimateFwhmOutputs`).
    """
    params = metric_estimate_fwhm_params(
        surface=surface,
        metric_in=metric_in,
        demean=demean,
        column=column,
        roi_metric=roi_metric,
    )
    return metric_estimate_fwhm_execute(params, runner)


__all__ = [
    "METRIC_ESTIMATE_FWHM_METADATA",
    "MetricEstimateFwhmOutputs",
    "MetricEstimateFwhmParamsDict",
    "MetricEstimateFwhmParamsDictTagged",
    "metric_estimate_fwhm",
    "metric_estimate_fwhm_execute",
    "metric_estimate_fwhm_params",
]
