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

import typing
import pathlib
from styxdefs import *

METRIC_ERODE_METADATA = Metadata(
    id="13e8b65243f7eb68a8e3480c1d899b0d9d55567e.boutiques",
    name="metric-erode",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


MetricErodeParameters = typing.TypedDict('MetricErodeParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/metric-erode"]],
    "metric": InputPathType,
    "surface": InputPathType,
    "distance": float,
    "metric_out": str,
    "opt_roi_roi_metric": typing.NotRequired[InputPathType | None],
    "opt_column_column": typing.NotRequired[str | None],
    "opt_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})
MetricErodeParametersTagged = typing.TypedDict('MetricErodeParametersTagged', {
    "@type": typing.Literal["workbench/metric-erode"],
    "metric": InputPathType,
    "surface": InputPathType,
    "distance": float,
    "metric_out": str,
    "opt_roi_roi_metric": typing.NotRequired[InputPathType | None],
    "opt_column_column": typing.NotRequired[str | None],
    "opt_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})


class MetricErodeOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MetricErodeParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    metric_out: OutputPathType
    """the output metric"""


def metric_erode_params(
    metric: InputPathType,
    surface: InputPathType,
    distance: float,
    metric_out: str,
    opt_roi_roi_metric: InputPathType | None = None,
    opt_column_column: str | None = None,
    opt_corrected_areas_area_metric: InputPathType | None = None,
) -> MetricErodeParametersTagged:
    """
    Build parameters.
    
    Args:
        metric: the metric file to erode.
        surface: the surface to compute on.
        distance: distance in mm to erode.
        metric_out: the output metric.
        opt_roi_roi_metric: assume values outside this roi are nonzero: metric\
            file, positive values denote vertices that have data.
        opt_column_column: select a single column to erode: the column number\
            or name.
        opt_corrected_areas_area_metric: vertex areas to use instead of\
            computing them from the surface: the corrected vertex areas, as a\
            metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/metric-erode",
        "metric": metric,
        "surface": surface,
        "distance": distance,
        "metric_out": metric_out,
    }
    if opt_roi_roi_metric is not None:
        params["opt_roi_roi_metric"] = opt_roi_roi_metric
    if opt_column_column is not None:
        params["opt_column_column"] = opt_column_column
    if opt_corrected_areas_area_metric is not None:
        params["opt_corrected_areas_area_metric"] = opt_corrected_areas_area_metric
    return params


def metric_erode_cargs(
    params: MetricErodeParameters,
    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("-metric-erode")
    cargs.append(execution.input_file(params.get("metric", None)))
    cargs.append(execution.input_file(params.get("surface", None)))
    cargs.append(str(params.get("distance", None)))
    cargs.append(params.get("metric_out", None))
    if params.get("opt_roi_roi_metric", None) is not None:
        cargs.extend([
            "-roi",
            execution.input_file(params.get("opt_roi_roi_metric", None))
        ])
    if params.get("opt_column_column", None) is not None:
        cargs.extend([
            "-column",
            params.get("opt_column_column", None)
        ])
    if params.get("opt_corrected_areas_area_metric", None) is not None:
        cargs.extend([
            "-corrected-areas",
            execution.input_file(params.get("opt_corrected_areas_area_metric", None))
        ])
    return cargs


def metric_erode_outputs(
    params: MetricErodeParameters,
    execution: Execution,
) -> MetricErodeOutputs:
    """
    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 = MetricErodeOutputs(
        root=execution.output_file("."),
        metric_out=execution.output_file(params.get("metric_out", None)),
    )
    return ret


def metric_erode_execute(
    params: MetricErodeParameters,
    runner: Runner | None = None,
) -> MetricErodeOutputs:
    """
    metric-erode
    
    Erode a metric file.
    
    Around each vertex with a value of zero, set surrounding vertices to zero.
    The surrounding vertices are all immediate neighbors and all vertices within
    the specified distance.
    
    Note that the -corrected-areas option uses an approximate correction for
    distance along the surface.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricErodeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_ERODE_METADATA)
    params = execution.params(params)
    cargs = metric_erode_cargs(params, execution)
    ret = metric_erode_outputs(params, execution)
    execution.run(cargs)
    return ret


def metric_erode(
    metric: InputPathType,
    surface: InputPathType,
    distance: float,
    metric_out: str,
    opt_roi_roi_metric: InputPathType | None = None,
    opt_column_column: str | None = None,
    opt_corrected_areas_area_metric: InputPathType | None = None,
    runner: Runner | None = None,
) -> MetricErodeOutputs:
    """
    metric-erode
    
    Erode a metric file.
    
    Around each vertex with a value of zero, set surrounding vertices to zero.
    The surrounding vertices are all immediate neighbors and all vertices within
    the specified distance.
    
    Note that the -corrected-areas option uses an approximate correction for
    distance along the surface.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        metric: the metric file to erode.
        surface: the surface to compute on.
        distance: distance in mm to erode.
        metric_out: the output metric.
        opt_roi_roi_metric: assume values outside this roi are nonzero: metric\
            file, positive values denote vertices that have data.
        opt_column_column: select a single column to erode: the column number\
            or name.
        opt_corrected_areas_area_metric: vertex areas to use instead of\
            computing them from the surface: the corrected vertex areas, as a\
            metric.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricErodeOutputs`).
    """
    params = metric_erode_params(
        metric=metric,
        surface=surface,
        distance=distance,
        metric_out=metric_out,
        opt_roi_roi_metric=opt_roi_roi_metric,
        opt_column_column=opt_column_column,
        opt_corrected_areas_area_metric=opt_corrected_areas_area_metric,
    )
    return metric_erode_execute(params, runner)


__all__ = [
    "METRIC_ERODE_METADATA",
    "MetricErodeOutputs",
    "metric_erode",
    "metric_erode_execute",
    "metric_erode_params",
]
