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

import typing
import pathlib
from styxdefs import *

LABEL_ERODE_METADATA = Metadata(
    id="99712b5dfa61e349e4c3839ddd13dfb8b7032631.boutiques",
    name="label-erode",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


LabelErodeParameters = typing.TypedDict('LabelErodeParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/label-erode"]],
    "label": InputPathType,
    "surface": InputPathType,
    "erode_dist": float,
    "label_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],
})
LabelErodeParametersTagged = typing.TypedDict('LabelErodeParametersTagged', {
    "@type": typing.Literal["workbench/label-erode"],
    "label": InputPathType,
    "surface": InputPathType,
    "erode_dist": float,
    "label_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 LabelErodeOutputs(typing.NamedTuple):
    """
    Output object returned when calling `LabelErodeParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    label_out: OutputPathType
    """the output label file"""


def label_erode_params(
    label: InputPathType,
    surface: InputPathType,
    erode_dist: float,
    label_out: str,
    opt_roi_roi_metric: InputPathType | None = None,
    opt_column_column: str | None = None,
    opt_corrected_areas_area_metric: InputPathType | None = None,
) -> LabelErodeParametersTagged:
    """
    Build parameters.
    
    Args:
        label: the input label.
        surface: the surface to erode on.
        erode_dist: distance in mm to erode the labels.
        label_out: the output label file.
        opt_roi_roi_metric: assume values outside this roi are labeled: 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/label-erode",
        "label": label,
        "surface": surface,
        "erode_dist": erode_dist,
        "label_out": label_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 label_erode_cargs(
    params: LabelErodeParameters,
    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("-label-erode")
    cargs.append(execution.input_file(params.get("label", None)))
    cargs.append(execution.input_file(params.get("surface", None)))
    cargs.append(str(params.get("erode_dist", None)))
    cargs.append(params.get("label_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 label_erode_outputs(
    params: LabelErodeParameters,
    execution: Execution,
) -> LabelErodeOutputs:
    """
    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 = LabelErodeOutputs(
        root=execution.output_file("."),
        label_out=execution.output_file(params.get("label_out", None)),
    )
    return ret


def label_erode_execute(
    params: LabelErodeParameters,
    runner: Runner | None = None,
) -> LabelErodeOutputs:
    """
    label-erode
    
    Erode a label file.
    
    Around each vertex that is unlabeled, set surrounding vertices to unlabeled.
    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 `LabelErodeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(LABEL_ERODE_METADATA)
    params = execution.params(params)
    cargs = label_erode_cargs(params, execution)
    ret = label_erode_outputs(params, execution)
    execution.run(cargs)
    return ret


def label_erode(
    label: InputPathType,
    surface: InputPathType,
    erode_dist: float,
    label_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,
) -> LabelErodeOutputs:
    """
    label-erode
    
    Erode a label file.
    
    Around each vertex that is unlabeled, set surrounding vertices to unlabeled.
    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:
        label: the input label.
        surface: the surface to erode on.
        erode_dist: distance in mm to erode the labels.
        label_out: the output label file.
        opt_roi_roi_metric: assume values outside this roi are labeled: 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 `LabelErodeOutputs`).
    """
    params = label_erode_params(
        label=label,
        surface=surface,
        erode_dist=erode_dist,
        label_out=label_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 label_erode_execute(params, runner)


__all__ = [
    "LABEL_ERODE_METADATA",
    "LabelErodeOutputs",
    "label_erode",
    "label_erode_execute",
    "label_erode_params",
]
