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

import typing
import pathlib
from styxdefs import *

VOLUME_PARCEL_SMOOTHING_METADATA = Metadata(
    id="d9e82f37b708bec47857be4b7298c862173c768b.boutiques",
    name="volume-parcel-smoothing",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


VolumeParcelSmoothingParameters = typing.TypedDict('VolumeParcelSmoothingParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/volume-parcel-smoothing"]],
    "data_volume": InputPathType,
    "label_volume": InputPathType,
    "kernel": float,
    "volume_out": str,
    "opt_fwhm": bool,
    "opt_fix_zeros": bool,
    "opt_subvolume_subvol": typing.NotRequired[str | None],
})
VolumeParcelSmoothingParametersTagged = typing.TypedDict('VolumeParcelSmoothingParametersTagged', {
    "@type": typing.Literal["workbench/volume-parcel-smoothing"],
    "data_volume": InputPathType,
    "label_volume": InputPathType,
    "kernel": float,
    "volume_out": str,
    "opt_fwhm": bool,
    "opt_fix_zeros": bool,
    "opt_subvolume_subvol": typing.NotRequired[str | None],
})


class VolumeParcelSmoothingOutputs(typing.NamedTuple):
    """
    Output object returned when calling `VolumeParcelSmoothingParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    volume_out: OutputPathType
    """the output volume"""


def volume_parcel_smoothing_params(
    data_volume: InputPathType,
    label_volume: InputPathType,
    kernel: float,
    volume_out: str,
    opt_fwhm: bool = False,
    opt_fix_zeros: bool = False,
    opt_subvolume_subvol: str | None = None,
) -> VolumeParcelSmoothingParametersTagged:
    """
    Build parameters.
    
    Args:
        data_volume: the volume to smooth.
        label_volume: a label volume containing the parcels to smooth.
        kernel: the size of the gaussian smoothing kernel in mm, as sigma by\
            default.
        volume_out: the output volume.
        opt_fwhm: smoothing kernel size is FWHM, not sigma.
        opt_fix_zeros: treat zero values as not being data.
        opt_subvolume_subvol: select a single subvolume to smooth: the\
            subvolume number or name.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/volume-parcel-smoothing",
        "data_volume": data_volume,
        "label_volume": label_volume,
        "kernel": kernel,
        "volume_out": volume_out,
        "opt_fwhm": opt_fwhm,
        "opt_fix_zeros": opt_fix_zeros,
    }
    if opt_subvolume_subvol is not None:
        params["opt_subvolume_subvol"] = opt_subvolume_subvol
    return params


def volume_parcel_smoothing_cargs(
    params: VolumeParcelSmoothingParameters,
    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("-volume-parcel-smoothing")
    cargs.append(execution.input_file(params.get("data_volume", None)))
    cargs.append(execution.input_file(params.get("label_volume", None)))
    cargs.append(str(params.get("kernel", None)))
    cargs.append(params.get("volume_out", None))
    if params.get("opt_fwhm", False):
        cargs.append("-fwhm")
    if params.get("opt_fix_zeros", False):
        cargs.append("-fix-zeros")
    if params.get("opt_subvolume_subvol", None) is not None:
        cargs.extend([
            "-subvolume",
            params.get("opt_subvolume_subvol", None)
        ])
    return cargs


def volume_parcel_smoothing_outputs(
    params: VolumeParcelSmoothingParameters,
    execution: Execution,
) -> VolumeParcelSmoothingOutputs:
    """
    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 = VolumeParcelSmoothingOutputs(
        root=execution.output_file("."),
        volume_out=execution.output_file(params.get("volume_out", None)),
    )
    return ret


def volume_parcel_smoothing_execute(
    params: VolumeParcelSmoothingParameters,
    runner: Runner | None = None,
) -> VolumeParcelSmoothingOutputs:
    """
    volume-parcel-smoothing
    
    Smooth parcels in a volume separately.
    
    The volume is smoothed within each label in the label volume using data only
    from within the label. Equivalent to running volume smoothing with ROIs
    matching each label separately, then adding the resulting volumes, but
    faster.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeParcelSmoothingOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_PARCEL_SMOOTHING_METADATA)
    params = execution.params(params)
    cargs = volume_parcel_smoothing_cargs(params, execution)
    ret = volume_parcel_smoothing_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_parcel_smoothing(
    data_volume: InputPathType,
    label_volume: InputPathType,
    kernel: float,
    volume_out: str,
    opt_fwhm: bool = False,
    opt_fix_zeros: bool = False,
    opt_subvolume_subvol: str | None = None,
    runner: Runner | None = None,
) -> VolumeParcelSmoothingOutputs:
    """
    volume-parcel-smoothing
    
    Smooth parcels in a volume separately.
    
    The volume is smoothed within each label in the label volume using data only
    from within the label. Equivalent to running volume smoothing with ROIs
    matching each label separately, then adding the resulting volumes, but
    faster.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        data_volume: the volume to smooth.
        label_volume: a label volume containing the parcels to smooth.
        kernel: the size of the gaussian smoothing kernel in mm, as sigma by\
            default.
        volume_out: the output volume.
        opt_fwhm: smoothing kernel size is FWHM, not sigma.
        opt_fix_zeros: treat zero values as not being data.
        opt_subvolume_subvol: select a single subvolume to smooth: the\
            subvolume number or name.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeParcelSmoothingOutputs`).
    """
    params = volume_parcel_smoothing_params(
        data_volume=data_volume,
        label_volume=label_volume,
        kernel=kernel,
        volume_out=volume_out,
        opt_fwhm=opt_fwhm,
        opt_fix_zeros=opt_fix_zeros,
        opt_subvolume_subvol=opt_subvolume_subvol,
    )
    return volume_parcel_smoothing_execute(params, runner)


__all__ = [
    "VOLUME_PARCEL_SMOOTHING_METADATA",
    "VolumeParcelSmoothingOutputs",
    "volume_parcel_smoothing",
    "volume_parcel_smoothing_execute",
    "volume_parcel_smoothing_params",
]
