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

import typing
import pathlib
from styxdefs import *
import dataclasses

METRIC_RESAMPLE_METADATA = Metadata(
    id="5e7483c2072fc7367c47eae4f6c3d880468b38fd.boutiques",
    name="metric-resample",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


@dataclasses.dataclass
class MetricResampleAreaSurfs:
    """
    specify surfaces to do vertex area correction based on.
    """
    current_area: InputPathType
    """a relevant anatomical surface with <current-sphere> mesh"""
    new_area: InputPathType
    """a relevant anatomical surface with <new-sphere> mesh"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-area-surfs")
        cargs.append(execution.input_file(self.current_area))
        cargs.append(execution.input_file(self.new_area))
        return cargs


@dataclasses.dataclass
class MetricResampleAreaMetrics:
    """
    specify vertex area metrics to do area correction based on.
    """
    current_area: InputPathType
    """a metric file with vertex areas for <current-sphere> mesh"""
    new_area: InputPathType
    """a metric file with vertex areas for <new-sphere> mesh"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-area-metrics")
        cargs.append(execution.input_file(self.current_area))
        cargs.append(execution.input_file(self.new_area))
        return cargs


class MetricResampleOutputs(typing.NamedTuple):
    """
    Output object returned when calling `metric_resample(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    metric_out: OutputPathType
    """the output metric"""
    roi_out: OutputPathType
    """the output roi as a metric"""


def metric_resample(
    metric_in: InputPathType,
    current_sphere: InputPathType,
    new_sphere: InputPathType,
    method: str,
    metric_out: str,
    roi_out: str,
    area_surfs: MetricResampleAreaSurfs | None = None,
    area_metrics: MetricResampleAreaMetrics | None = None,
    opt_current_roi_roi_metric: InputPathType | None = None,
    opt_valid_roi_out: bool = False,
    opt_largest: bool = False,
    opt_bypass_sphere_check: bool = False,
    runner: Runner | None = None,
) -> MetricResampleOutputs:
    """
    Resample a metric file to a different mesh.
    
    Resamples a metric file, given two spherical surfaces that are in register.
    If ADAP_BARY_AREA is used, exactly one of -area-surfs or -area-metrics must
    be specified.
    
    The ADAP_BARY_AREA method is recommended for ordinary metric data, because
    it should use all data while downsampling, unlike BARYCENTRIC. The
    recommended areas option for most data is individual midthicknesses for
    individual data, and averaged vertex area metrics from individual
    midthicknesses for group average data.
    
    The -current-roi option only masks the input, the output may be slightly
    dilated in comparison, consider using -metric-mask on the output when using
    -current-roi.
    
    The -largest option results in nearest vertex behavior when used with
    BARYCENTRIC. When resampling a binary metric, consider thresholding at 0.5
    after resampling rather than using -largest.
    
    The <method> argument must be one of the following:
    
    ADAP_BARY_AREA
    BARYCENTRIC
    .
    
    Author: Washington University School of Medicin
    
    Args:
        metric_in: the metric file to resample.
        current_sphere: a sphere surface with the mesh that the metric is\
            currently on.
        new_sphere: a sphere surface that is in register with <current-sphere>\
            and has the desired output mesh.
        method: the method name.
        metric_out: the output metric.
        roi_out: the output roi as a metric.
        area_surfs: specify surfaces to do vertex area correction based on.
        area_metrics: specify vertex area metrics to do area correction based\
            on.
        opt_current_roi_roi_metric: use an input roi on the current mesh to\
            exclude non-data vertices: the roi, as a metric file.
        opt_valid_roi_out: output the ROI of vertices that got data from valid\
            source vertices.
        opt_largest: use only the value of the vertex with the largest weight.
        opt_bypass_sphere_check: ADVANCED: allow the current and new 'spheres'\
            to have arbitrary shape as long as they follow the same contour.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricResampleOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_RESAMPLE_METADATA)
    cargs = []
    cargs.append("wb_command")
    cargs.append("-metric-resample")
    cargs.append(execution.input_file(metric_in))
    cargs.append(execution.input_file(current_sphere))
    cargs.append(execution.input_file(new_sphere))
    cargs.append(method)
    cargs.append(metric_out)
    if area_surfs is not None:
        cargs.extend(area_surfs.run(execution))
    if area_metrics is not None:
        cargs.extend(area_metrics.run(execution))
    if opt_current_roi_roi_metric is not None:
        cargs.extend([
            "-current-roi",
            execution.input_file(opt_current_roi_roi_metric)
        ])
    if opt_valid_roi_out:
        cargs.append("-valid-roi-out")
    cargs.append(roi_out)
    if opt_largest:
        cargs.append("-largest")
    if opt_bypass_sphere_check:
        cargs.append("-bypass-sphere-check")
    ret = MetricResampleOutputs(
        root=execution.output_file("."),
        metric_out=execution.output_file(metric_out),
        roi_out=execution.output_file(roi_out),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "METRIC_RESAMPLE_METADATA",
    "MetricResampleAreaMetrics",
    "MetricResampleAreaSurfs",
    "MetricResampleOutputs",
    "metric_resample",
]
