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

import typing
import pathlib
from styxdefs import *

VOLUME_SMOOTHING_METADATA = Metadata(
    id="16d345c3991b1be3c6200b8b8d0e7e17cdd8c48a.boutiques",
    name="volume-smoothing",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


VolumeSmoothingParameters = typing.TypedDict('VolumeSmoothingParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/volume-smoothing"]],
    "volume_in": InputPathType,
    "kernel": float,
    "volume_out": str,
    "opt_fwhm": bool,
    "opt_roi_roivol": typing.NotRequired[InputPathType | None],
    "opt_fix_zeros": bool,
    "opt_subvolume_subvol": typing.NotRequired[str | None],
})
VolumeSmoothingParametersTagged = typing.TypedDict('VolumeSmoothingParametersTagged', {
    "@type": typing.Literal["workbench/volume-smoothing"],
    "volume_in": InputPathType,
    "kernel": float,
    "volume_out": str,
    "opt_fwhm": bool,
    "opt_roi_roivol": typing.NotRequired[InputPathType | None],
    "opt_fix_zeros": bool,
    "opt_subvolume_subvol": typing.NotRequired[str | None],
})


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


def volume_smoothing_params(
    volume_in: InputPathType,
    kernel: float,
    volume_out: str,
    opt_fwhm: bool = False,
    opt_roi_roivol: InputPathType | None = None,
    opt_fix_zeros: bool = False,
    opt_subvolume_subvol: str | None = None,
) -> VolumeSmoothingParametersTagged:
    """
    Build parameters.
    
    Args:
        volume_in: the volume to smooth.
        kernel: the size of the gaussian smoothing kernel in mm, as sigma by\
            default.
        volume_out: the output volume.
        opt_fwhm: kernel size is FWHM, not sigma.
        opt_roi_roivol: smooth only from data within an ROI: the volume to use\
            as an ROI.
        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-smoothing",
        "volume_in": volume_in,
        "kernel": kernel,
        "volume_out": volume_out,
        "opt_fwhm": opt_fwhm,
        "opt_fix_zeros": opt_fix_zeros,
    }
    if opt_roi_roivol is not None:
        params["opt_roi_roivol"] = opt_roi_roivol
    if opt_subvolume_subvol is not None:
        params["opt_subvolume_subvol"] = opt_subvolume_subvol
    return params


def volume_smoothing_cargs(
    params: VolumeSmoothingParameters,
    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-smoothing")
    cargs.append(execution.input_file(params.get("volume_in", 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_roi_roivol", None) is not None:
        cargs.extend([
            "-roi",
            execution.input_file(params.get("opt_roi_roivol", None))
        ])
    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_smoothing_outputs(
    params: VolumeSmoothingParameters,
    execution: Execution,
) -> VolumeSmoothingOutputs:
    """
    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 = VolumeSmoothingOutputs(
        root=execution.output_file("."),
        volume_out=execution.output_file(params.get("volume_out", None)),
    )
    return ret


def volume_smoothing_execute(
    params: VolumeSmoothingParameters,
    runner: Runner | None = None,
) -> VolumeSmoothingOutputs:
    """
    volume-smoothing
    
    Smooth a volume file.
    
    Gaussian smoothing for volumes. By default, smooths all subvolumes with no
    ROI, if ROI is given, only positive voxels in the ROI volume have their
    values used, and all other voxels are set to zero. Smoothing a
    non-orthogonal volume will be significantly slower, because the operation
    cannot be separated into 1-dimensional smoothings without distorting the
    kernel shape.
    
    The -fix-zeros option causes the smoothing to not use an input value if it
    is zero, but still write a smoothed value to the voxel. This is useful for
    zeros that indicate lack of information, preventing them from pulling down
    the intensity of nearby voxels, while giving the zero an extrapolated value.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeSmoothingOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_SMOOTHING_METADATA)
    params = execution.params(params)
    cargs = volume_smoothing_cargs(params, execution)
    ret = volume_smoothing_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_smoothing(
    volume_in: InputPathType,
    kernel: float,
    volume_out: str,
    opt_fwhm: bool = False,
    opt_roi_roivol: InputPathType | None = None,
    opt_fix_zeros: bool = False,
    opt_subvolume_subvol: str | None = None,
    runner: Runner | None = None,
) -> VolumeSmoothingOutputs:
    """
    volume-smoothing
    
    Smooth a volume file.
    
    Gaussian smoothing for volumes. By default, smooths all subvolumes with no
    ROI, if ROI is given, only positive voxels in the ROI volume have their
    values used, and all other voxels are set to zero. Smoothing a
    non-orthogonal volume will be significantly slower, because the operation
    cannot be separated into 1-dimensional smoothings without distorting the
    kernel shape.
    
    The -fix-zeros option causes the smoothing to not use an input value if it
    is zero, but still write a smoothed value to the voxel. This is useful for
    zeros that indicate lack of information, preventing them from pulling down
    the intensity of nearby voxels, while giving the zero an extrapolated value.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        volume_in: the volume to smooth.
        kernel: the size of the gaussian smoothing kernel in mm, as sigma by\
            default.
        volume_out: the output volume.
        opt_fwhm: kernel size is FWHM, not sigma.
        opt_roi_roivol: smooth only from data within an ROI: the volume to use\
            as an ROI.
        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 `VolumeSmoothingOutputs`).
    """
    params = volume_smoothing_params(
        volume_in=volume_in,
        kernel=kernel,
        volume_out=volume_out,
        opt_fwhm=opt_fwhm,
        opt_roi_roivol=opt_roi_roivol,
        opt_fix_zeros=opt_fix_zeros,
        opt_subvolume_subvol=opt_subvolume_subvol,
    )
    return volume_smoothing_execute(params, runner)


__all__ = [
    "VOLUME_SMOOTHING_METADATA",
    "VolumeSmoothingOutputs",
    "volume_smoothing",
    "volume_smoothing_execute",
    "volume_smoothing_params",
]
