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

import typing
import pathlib
from styxdefs import *

METRIC_REMOVE_ISLANDS_METADATA = Metadata(
    id="e985bca06df5a5d0c37e22c118468bf7cef4f5d3.boutiques",
    name="metric-remove-islands",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


MetricRemoveIslandsParameters = typing.TypedDict('MetricRemoveIslandsParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/metric-remove-islands"]],
    "surface": InputPathType,
    "metric_in": InputPathType,
    "metric_out": str,
    "opt_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})
MetricRemoveIslandsParametersTagged = typing.TypedDict('MetricRemoveIslandsParametersTagged', {
    "@type": typing.Literal["workbench/metric-remove-islands"],
    "surface": InputPathType,
    "metric_in": InputPathType,
    "metric_out": str,
    "opt_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})


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


def metric_remove_islands_params(
    surface: InputPathType,
    metric_in: InputPathType,
    metric_out: str,
    opt_corrected_areas_area_metric: InputPathType | None = None,
) -> MetricRemoveIslandsParametersTagged:
    """
    Build parameters.
    
    Args:
        surface: the surface to use for neighbor information.
        metric_in: the input ROI metric.
        metric_out: the output ROI metric.
        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-remove-islands",
        "surface": surface,
        "metric_in": metric_in,
        "metric_out": metric_out,
    }
    if opt_corrected_areas_area_metric is not None:
        params["opt_corrected_areas_area_metric"] = opt_corrected_areas_area_metric
    return params


def metric_remove_islands_cargs(
    params: MetricRemoveIslandsParameters,
    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-remove-islands")
    cargs.append(execution.input_file(params.get("surface", None)))
    cargs.append(execution.input_file(params.get("metric_in", None)))
    cargs.append(params.get("metric_out", 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_remove_islands_outputs(
    params: MetricRemoveIslandsParameters,
    execution: Execution,
) -> MetricRemoveIslandsOutputs:
    """
    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 = MetricRemoveIslandsOutputs(
        root=execution.output_file("."),
        metric_out=execution.output_file(params.get("metric_out", None)),
    )
    return ret


def metric_remove_islands_execute(
    params: MetricRemoveIslandsParameters,
    runner: Runner | None = None,
) -> MetricRemoveIslandsOutputs:
    """
    metric-remove-islands
    
    Remove islands from an roi metric.
    
    Finds all connected areas in the ROI, and zeros out all but the largest one,
    in terms of surface area.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricRemoveIslandsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_REMOVE_ISLANDS_METADATA)
    params = execution.params(params)
    cargs = metric_remove_islands_cargs(params, execution)
    ret = metric_remove_islands_outputs(params, execution)
    execution.run(cargs)
    return ret


def metric_remove_islands(
    surface: InputPathType,
    metric_in: InputPathType,
    metric_out: str,
    opt_corrected_areas_area_metric: InputPathType | None = None,
    runner: Runner | None = None,
) -> MetricRemoveIslandsOutputs:
    """
    metric-remove-islands
    
    Remove islands from an roi metric.
    
    Finds all connected areas in the ROI, and zeros out all but the largest one,
    in terms of surface area.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        surface: the surface to use for neighbor information.
        metric_in: the input ROI metric.
        metric_out: the output ROI metric.
        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 `MetricRemoveIslandsOutputs`).
    """
    params = metric_remove_islands_params(
        surface=surface,
        metric_in=metric_in,
        metric_out=metric_out,
        opt_corrected_areas_area_metric=opt_corrected_areas_area_metric,
    )
    return metric_remove_islands_execute(params, runner)


__all__ = [
    "METRIC_REMOVE_ISLANDS_METADATA",
    "MetricRemoveIslandsOutputs",
    "metric_remove_islands",
    "metric_remove_islands_execute",
    "metric_remove_islands_params",
]
