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

import typing
import pathlib
from styxdefs import *

CIFTI_SMOOTHING_METADATA = Metadata(
    id="0b87cc9cdd0f0460a8ebb1583ddeff5398d57bd4.boutiques",
    name="cifti-smoothing",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


CiftiSmoothingLeftSurfaceParameters = typing.TypedDict('CiftiSmoothingLeftSurfaceParameters', {
    "@type": typing.NotRequired[typing.Literal["left_surface"]],
    "surface": InputPathType,
    "opt_left_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})
CiftiSmoothingLeftSurfaceParametersTagged = typing.TypedDict('CiftiSmoothingLeftSurfaceParametersTagged', {
    "@type": typing.Literal["left_surface"],
    "surface": InputPathType,
    "opt_left_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})


CiftiSmoothingRightSurfaceParameters = typing.TypedDict('CiftiSmoothingRightSurfaceParameters', {
    "@type": typing.NotRequired[typing.Literal["right_surface"]],
    "surface": InputPathType,
    "opt_right_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})
CiftiSmoothingRightSurfaceParametersTagged = typing.TypedDict('CiftiSmoothingRightSurfaceParametersTagged', {
    "@type": typing.Literal["right_surface"],
    "surface": InputPathType,
    "opt_right_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})


CiftiSmoothingCerebellumSurfaceParameters = typing.TypedDict('CiftiSmoothingCerebellumSurfaceParameters', {
    "@type": typing.NotRequired[typing.Literal["cerebellum_surface"]],
    "surface": InputPathType,
    "opt_cerebellum_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})
CiftiSmoothingCerebellumSurfaceParametersTagged = typing.TypedDict('CiftiSmoothingCerebellumSurfaceParametersTagged', {
    "@type": typing.Literal["cerebellum_surface"],
    "surface": InputPathType,
    "opt_cerebellum_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})


CiftiSmoothingParameters = typing.TypedDict('CiftiSmoothingParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/cifti-smoothing"]],
    "cifti": InputPathType,
    "surface_kernel": float,
    "volume_kernel": float,
    "direction": str,
    "cifti_out": str,
    "opt_fwhm": bool,
    "left_surface": typing.NotRequired[CiftiSmoothingLeftSurfaceParameters | None],
    "right_surface": typing.NotRequired[CiftiSmoothingRightSurfaceParameters | None],
    "cerebellum_surface": typing.NotRequired[CiftiSmoothingCerebellumSurfaceParameters | None],
    "opt_cifti_roi_roi_cifti": typing.NotRequired[InputPathType | None],
    "opt_fix_zeros_volume": bool,
    "opt_fix_zeros_surface": bool,
    "opt_merged_volume": bool,
})
CiftiSmoothingParametersTagged = typing.TypedDict('CiftiSmoothingParametersTagged', {
    "@type": typing.Literal["workbench/cifti-smoothing"],
    "cifti": InputPathType,
    "surface_kernel": float,
    "volume_kernel": float,
    "direction": str,
    "cifti_out": str,
    "opt_fwhm": bool,
    "left_surface": typing.NotRequired[CiftiSmoothingLeftSurfaceParameters | None],
    "right_surface": typing.NotRequired[CiftiSmoothingRightSurfaceParameters | None],
    "cerebellum_surface": typing.NotRequired[CiftiSmoothingCerebellumSurfaceParameters | None],
    "opt_cifti_roi_roi_cifti": typing.NotRequired[InputPathType | None],
    "opt_fix_zeros_volume": bool,
    "opt_fix_zeros_surface": bool,
    "opt_merged_volume": bool,
})


def cifti_smoothing_left_surface_params(
    surface: InputPathType,
    opt_left_corrected_areas_area_metric: InputPathType | None = None,
) -> CiftiSmoothingLeftSurfaceParametersTagged:
    """
    Build parameters.
    
    Args:
        surface: the left surface file.
        opt_left_corrected_areas_area_metric: vertex areas to use instead of\
            computing them from the left surface: the corrected vertex areas, as a\
            metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "left_surface",
        "surface": surface,
    }
    if opt_left_corrected_areas_area_metric is not None:
        params["opt_left_corrected_areas_area_metric"] = opt_left_corrected_areas_area_metric
    return params


def cifti_smoothing_left_surface_cargs(
    params: CiftiSmoothingLeftSurfaceParameters,
    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("-left-surface")
    cargs.append(execution.input_file(params.get("surface", None)))
    if params.get("opt_left_corrected_areas_area_metric", None) is not None:
        cargs.extend([
            "-left-corrected-areas",
            execution.input_file(params.get("opt_left_corrected_areas_area_metric", None))
        ])
    return cargs


def cifti_smoothing_right_surface_params(
    surface: InputPathType,
    opt_right_corrected_areas_area_metric: InputPathType | None = None,
) -> CiftiSmoothingRightSurfaceParametersTagged:
    """
    Build parameters.
    
    Args:
        surface: the right surface file.
        opt_right_corrected_areas_area_metric: vertex areas to use instead of\
            computing them from the right surface: the corrected vertex areas, as a\
            metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "right_surface",
        "surface": surface,
    }
    if opt_right_corrected_areas_area_metric is not None:
        params["opt_right_corrected_areas_area_metric"] = opt_right_corrected_areas_area_metric
    return params


def cifti_smoothing_right_surface_cargs(
    params: CiftiSmoothingRightSurfaceParameters,
    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("-right-surface")
    cargs.append(execution.input_file(params.get("surface", None)))
    if params.get("opt_right_corrected_areas_area_metric", None) is not None:
        cargs.extend([
            "-right-corrected-areas",
            execution.input_file(params.get("opt_right_corrected_areas_area_metric", None))
        ])
    return cargs


def cifti_smoothing_cerebellum_surface_params(
    surface: InputPathType,
    opt_cerebellum_corrected_areas_area_metric: InputPathType | None = None,
) -> CiftiSmoothingCerebellumSurfaceParametersTagged:
    """
    Build parameters.
    
    Args:
        surface: the cerebellum surface file.
        opt_cerebellum_corrected_areas_area_metric: vertex areas to use instead\
            of computing them from the cerebellum surface: the corrected vertex\
            areas, as a metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "cerebellum_surface",
        "surface": surface,
    }
    if opt_cerebellum_corrected_areas_area_metric is not None:
        params["opt_cerebellum_corrected_areas_area_metric"] = opt_cerebellum_corrected_areas_area_metric
    return params


def cifti_smoothing_cerebellum_surface_cargs(
    params: CiftiSmoothingCerebellumSurfaceParameters,
    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("-cerebellum-surface")
    cargs.append(execution.input_file(params.get("surface", None)))
    if params.get("opt_cerebellum_corrected_areas_area_metric", None) is not None:
        cargs.extend([
            "-cerebellum-corrected-areas",
            execution.input_file(params.get("opt_cerebellum_corrected_areas_area_metric", None))
        ])
    return cargs


class CiftiSmoothingOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiSmoothingParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    cifti_out: OutputPathType
    """the output cifti"""


def cifti_smoothing_params(
    cifti: InputPathType,
    surface_kernel: float,
    volume_kernel: float,
    direction: str,
    cifti_out: str,
    opt_fwhm: bool = False,
    left_surface: CiftiSmoothingLeftSurfaceParameters | None = None,
    right_surface: CiftiSmoothingRightSurfaceParameters | None = None,
    cerebellum_surface: CiftiSmoothingCerebellumSurfaceParameters | None = None,
    opt_cifti_roi_roi_cifti: InputPathType | None = None,
    opt_fix_zeros_volume: bool = False,
    opt_fix_zeros_surface: bool = False,
    opt_merged_volume: bool = False,
) -> CiftiSmoothingParametersTagged:
    """
    Build parameters.
    
    Args:
        cifti: the input cifti.
        surface_kernel: the size of the gaussian surface smoothing kernel in\
            mm, as sigma by default.
        volume_kernel: the size of the gaussian volume smoothing kernel in mm,\
            as sigma by default.
        direction: which dimension to smooth along, ROW or COLUMN.
        cifti_out: the output cifti.
        opt_fwhm: kernel sizes are FWHM, not sigma.
        left_surface: specify the left surface to use.
        right_surface: specify the right surface to use.
        cerebellum_surface: specify the cerebellum surface to use.
        opt_cifti_roi_roi_cifti: smooth only within regions of interest: the\
            regions to smooth within, as a cifti file.
        opt_fix_zeros_volume: treat values of zero in the volume as missing\
            data.
        opt_fix_zeros_surface: treat values of zero on the surface as missing\
            data.
        opt_merged_volume: smooth across subcortical structure boundaries.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-smoothing",
        "cifti": cifti,
        "surface_kernel": surface_kernel,
        "volume_kernel": volume_kernel,
        "direction": direction,
        "cifti_out": cifti_out,
        "opt_fwhm": opt_fwhm,
        "opt_fix_zeros_volume": opt_fix_zeros_volume,
        "opt_fix_zeros_surface": opt_fix_zeros_surface,
        "opt_merged_volume": opt_merged_volume,
    }
    if left_surface is not None:
        params["left_surface"] = left_surface
    if right_surface is not None:
        params["right_surface"] = right_surface
    if cerebellum_surface is not None:
        params["cerebellum_surface"] = cerebellum_surface
    if opt_cifti_roi_roi_cifti is not None:
        params["opt_cifti_roi_roi_cifti"] = opt_cifti_roi_roi_cifti
    return params


def cifti_smoothing_cargs(
    params: CiftiSmoothingParameters,
    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("-cifti-smoothing")
    cargs.append(execution.input_file(params.get("cifti", None)))
    cargs.append(str(params.get("surface_kernel", None)))
    cargs.append(str(params.get("volume_kernel", None)))
    cargs.append(params.get("direction", None))
    cargs.append(params.get("cifti_out", None))
    if params.get("opt_fwhm", False):
        cargs.append("-fwhm")
    if params.get("left_surface", None) is not None:
        cargs.extend(cifti_smoothing_left_surface_cargs(params.get("left_surface", None), execution))
    if params.get("right_surface", None) is not None:
        cargs.extend(cifti_smoothing_right_surface_cargs(params.get("right_surface", None), execution))
    if params.get("cerebellum_surface", None) is not None:
        cargs.extend(cifti_smoothing_cerebellum_surface_cargs(params.get("cerebellum_surface", None), execution))
    if params.get("opt_cifti_roi_roi_cifti", None) is not None:
        cargs.extend([
            "-cifti-roi",
            execution.input_file(params.get("opt_cifti_roi_roi_cifti", None))
        ])
    if params.get("opt_fix_zeros_volume", False):
        cargs.append("-fix-zeros-volume")
    if params.get("opt_fix_zeros_surface", False):
        cargs.append("-fix-zeros-surface")
    if params.get("opt_merged_volume", False):
        cargs.append("-merged-volume")
    return cargs


def cifti_smoothing_outputs(
    params: CiftiSmoothingParameters,
    execution: Execution,
) -> CiftiSmoothingOutputs:
    """
    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 = CiftiSmoothingOutputs(
        root=execution.output_file("."),
        cifti_out=execution.output_file(params.get("cifti_out", None)),
    )
    return ret


def cifti_smoothing_execute(
    params: CiftiSmoothingParameters,
    runner: Runner | None = None,
) -> CiftiSmoothingOutputs:
    """
    cifti-smoothing
    
    Smooth a cifti file.
    
    The input cifti file must have a brain models mapping on the chosen
    dimension, columns for .dtseries, and either for .dconn. By default, data in
    different structures is smoothed independently (i.e., "parcel constrained"
    smoothing), so volume structures that touch do not smooth across this
    boundary. Specify -merged-volume to ignore these boundaries. Surface
    smoothing uses the GEO_GAUSS_AREA smoothing method.
    
    The -*-corrected-areas options are intended for when it is unavoidable to
    smooth on group average surfaces, it is only an approximate correction for
    the reduction of structure in a group average surface. It is better to
    smooth the data on individuals before averaging, when feasible.
    
    The -fix-zeros-* options will treat values of zero as lack of data, and not
    use that value when generating the smoothed values, but will fill zeros with
    extrapolated values. The ROI should have a brain models mapping along
    columns, exactly matching the mapping of the chosen direction in the input
    file. Data outside the ROI is ignored.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiSmoothingOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_SMOOTHING_METADATA)
    params = execution.params(params)
    cargs = cifti_smoothing_cargs(params, execution)
    ret = cifti_smoothing_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_smoothing(
    cifti: InputPathType,
    surface_kernel: float,
    volume_kernel: float,
    direction: str,
    cifti_out: str,
    opt_fwhm: bool = False,
    left_surface: CiftiSmoothingLeftSurfaceParameters | None = None,
    right_surface: CiftiSmoothingRightSurfaceParameters | None = None,
    cerebellum_surface: CiftiSmoothingCerebellumSurfaceParameters | None = None,
    opt_cifti_roi_roi_cifti: InputPathType | None = None,
    opt_fix_zeros_volume: bool = False,
    opt_fix_zeros_surface: bool = False,
    opt_merged_volume: bool = False,
    runner: Runner | None = None,
) -> CiftiSmoothingOutputs:
    """
    cifti-smoothing
    
    Smooth a cifti file.
    
    The input cifti file must have a brain models mapping on the chosen
    dimension, columns for .dtseries, and either for .dconn. By default, data in
    different structures is smoothed independently (i.e., "parcel constrained"
    smoothing), so volume structures that touch do not smooth across this
    boundary. Specify -merged-volume to ignore these boundaries. Surface
    smoothing uses the GEO_GAUSS_AREA smoothing method.
    
    The -*-corrected-areas options are intended for when it is unavoidable to
    smooth on group average surfaces, it is only an approximate correction for
    the reduction of structure in a group average surface. It is better to
    smooth the data on individuals before averaging, when feasible.
    
    The -fix-zeros-* options will treat values of zero as lack of data, and not
    use that value when generating the smoothed values, but will fill zeros with
    extrapolated values. The ROI should have a brain models mapping along
    columns, exactly matching the mapping of the chosen direction in the input
    file. Data outside the ROI is ignored.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        cifti: the input cifti.
        surface_kernel: the size of the gaussian surface smoothing kernel in\
            mm, as sigma by default.
        volume_kernel: the size of the gaussian volume smoothing kernel in mm,\
            as sigma by default.
        direction: which dimension to smooth along, ROW or COLUMN.
        cifti_out: the output cifti.
        opt_fwhm: kernel sizes are FWHM, not sigma.
        left_surface: specify the left surface to use.
        right_surface: specify the right surface to use.
        cerebellum_surface: specify the cerebellum surface to use.
        opt_cifti_roi_roi_cifti: smooth only within regions of interest: the\
            regions to smooth within, as a cifti file.
        opt_fix_zeros_volume: treat values of zero in the volume as missing\
            data.
        opt_fix_zeros_surface: treat values of zero on the surface as missing\
            data.
        opt_merged_volume: smooth across subcortical structure boundaries.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiSmoothingOutputs`).
    """
    params = cifti_smoothing_params(
        cifti=cifti,
        surface_kernel=surface_kernel,
        volume_kernel=volume_kernel,
        direction=direction,
        cifti_out=cifti_out,
        opt_fwhm=opt_fwhm,
        left_surface=left_surface,
        right_surface=right_surface,
        cerebellum_surface=cerebellum_surface,
        opt_cifti_roi_roi_cifti=opt_cifti_roi_roi_cifti,
        opt_fix_zeros_volume=opt_fix_zeros_volume,
        opt_fix_zeros_surface=opt_fix_zeros_surface,
        opt_merged_volume=opt_merged_volume,
    )
    return cifti_smoothing_execute(params, runner)


__all__ = [
    "CIFTI_SMOOTHING_METADATA",
    "CiftiSmoothingOutputs",
    "cifti_smoothing",
    "cifti_smoothing_cerebellum_surface_params",
    "cifti_smoothing_execute",
    "cifti_smoothing_left_surface_params",
    "cifti_smoothing_params",
    "cifti_smoothing_right_surface_params",
]
