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

import typing
import pathlib
from styxdefs import *

VOLUME_PARCEL_RESAMPLING_GENERIC_METADATA = Metadata(
    id="af4253f6abeeb8c49031f8d9530011d0fb4ffa9e.boutiques",
    name="volume-parcel-resampling-generic",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


VolumeParcelResamplingGenericParameters = typing.TypedDict('VolumeParcelResamplingGenericParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/volume-parcel-resampling-generic"]],
    "volume_in": InputPathType,
    "cur_parcels": InputPathType,
    "new_parcels": InputPathType,
    "kernel": float,
    "volume_out": str,
    "opt_fwhm": bool,
    "opt_fix_zeros": bool,
    "opt_subvolume_subvol": typing.NotRequired[str | None],
})
VolumeParcelResamplingGenericParametersTagged = typing.TypedDict('VolumeParcelResamplingGenericParametersTagged', {
    "@type": typing.Literal["workbench/volume-parcel-resampling-generic"],
    "volume_in": InputPathType,
    "cur_parcels": InputPathType,
    "new_parcels": InputPathType,
    "kernel": float,
    "volume_out": str,
    "opt_fwhm": bool,
    "opt_fix_zeros": bool,
    "opt_subvolume_subvol": typing.NotRequired[str | None],
})


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


def volume_parcel_resampling_generic_params(
    volume_in: InputPathType,
    cur_parcels: InputPathType,
    new_parcels: InputPathType,
    kernel: float,
    volume_out: str,
    opt_fwhm: bool = False,
    opt_fix_zeros: bool = False,
    opt_subvolume_subvol: str | None = None,
) -> VolumeParcelResamplingGenericParametersTagged:
    """
    Build parameters.
    
    Args:
        volume_in: the input data volume.
        cur_parcels: label volume of where the parcels currently are.
        new_parcels: label volume of where the parcels should be.
        kernel: gaussian kernel size in mm to smooth by during resampling, as\
            sigma by default.
        volume_out: 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 as input: the subvolume\
            number or name.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/volume-parcel-resampling-generic",
        "volume_in": volume_in,
        "cur_parcels": cur_parcels,
        "new_parcels": new_parcels,
        "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_resampling_generic_cargs(
    params: VolumeParcelResamplingGenericParameters,
    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-resampling-generic")
    cargs.append(execution.input_file(params.get("volume_in", None)))
    cargs.append(execution.input_file(params.get("cur_parcels", None)))
    cargs.append(execution.input_file(params.get("new_parcels", 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_resampling_generic_outputs(
    params: VolumeParcelResamplingGenericParameters,
    execution: Execution,
) -> VolumeParcelResamplingGenericOutputs:
    """
    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 = VolumeParcelResamplingGenericOutputs(
        root=execution.output_file("."),
        volume_out=execution.output_file(params.get("volume_out", None)),
    )
    return ret


def volume_parcel_resampling_generic_execute(
    params: VolumeParcelResamplingGenericParameters,
    runner: Runner | None = None,
) -> VolumeParcelResamplingGenericOutputs:
    """
    volume-parcel-resampling-generic
    
    Smooth and resample volume parcels from different volume space.
    
    Smooths and resamples the region inside each label in cur-parcels to the
    region of the same label name in new-parcels. Any voxels in the output label
    region but outside the input label region will be extrapolated from nearby
    data. 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, and after
    smoothing is complete, it will check for any remaining values of zero, and
    fill them in with extrapolated values. The output volume will use the volume
    space of new-parcels, which does not need to be in the same volume space as
    the input.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeParcelResamplingGenericOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_PARCEL_RESAMPLING_GENERIC_METADATA)
    params = execution.params(params)
    cargs = volume_parcel_resampling_generic_cargs(params, execution)
    ret = volume_parcel_resampling_generic_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_parcel_resampling_generic(
    volume_in: InputPathType,
    cur_parcels: InputPathType,
    new_parcels: 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,
) -> VolumeParcelResamplingGenericOutputs:
    """
    volume-parcel-resampling-generic
    
    Smooth and resample volume parcels from different volume space.
    
    Smooths and resamples the region inside each label in cur-parcels to the
    region of the same label name in new-parcels. Any voxels in the output label
    region but outside the input label region will be extrapolated from nearby
    data. 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, and after
    smoothing is complete, it will check for any remaining values of zero, and
    fill them in with extrapolated values. The output volume will use the volume
    space of new-parcels, which does not need to be in the same volume space as
    the input.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        volume_in: the input data volume.
        cur_parcels: label volume of where the parcels currently are.
        new_parcels: label volume of where the parcels should be.
        kernel: gaussian kernel size in mm to smooth by during resampling, as\
            sigma by default.
        volume_out: 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 as input: the subvolume\
            number or name.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeParcelResamplingGenericOutputs`).
    """
    params = volume_parcel_resampling_generic_params(
        volume_in=volume_in,
        cur_parcels=cur_parcels,
        new_parcels=new_parcels,
        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_resampling_generic_execute(params, runner)


__all__ = [
    "VOLUME_PARCEL_RESAMPLING_GENERIC_METADATA",
    "VolumeParcelResamplingGenericOutputs",
    "volume_parcel_resampling_generic",
    "volume_parcel_resampling_generic_execute",
    "volume_parcel_resampling_generic_params",
]
