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

import typing
import pathlib
from styxdefs import *
import dataclasses

MASKFILTER_METADATA = Metadata(
    id="64d09e2402719ae6eb1c2a4b1802b4a54c209de9.boutiques",
    name="maskfilter",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


@dataclasses.dataclass
class MaskfilterConfig:
    """
    temporarily set the value of an MRtrix config file entry.
    """
    key: str
    """temporarily set the value of an MRtrix config file entry."""
    value: str
    """temporarily set the value of an MRtrix config file entry."""
    
    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("-config")
        cargs.append(self.key)
        cargs.append(self.value)
        return cargs


class MaskfilterOutputs(typing.NamedTuple):
    """
    Output object returned when calling `maskfilter(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """the output image."""


def maskfilter(
    input_: InputPathType,
    filter_: str,
    output: str,
    scale: int | None = None,
    axes: list[int] | None = None,
    largest: bool = False,
    connectivity: bool = False,
    npass: int | None = None,
    extent: list[int] | None = None,
    strides: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MaskfilterConfig] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> MaskfilterOutputs:
    """
    Perform filtering operations on 3D / 4D mask images.
    
    The available filters are: clean, connect, dilate, erode, median.
    
    Each filter has its own unique set of optional parameters.
    
    References:
    
    .
    
    Author: Robert E. Smith (robert.smith@florey.edu.au), David Raffelt
    (david.raffelt@florey.edu.au), Thijs Dhollander (thijs.dhollander@gmail.com)
    and J-Donald Tournier (jdtournier@gmail.com)
    
    URL:
    https://mrtrix.readthedocs.io/en/latest/reference/commands/maskfilter.html
    
    Args:
        input_: the input image.
        filter_: the type of filter to be applied (clean, connect, dilate,\
            erode, median).
        output: the output image.
        scale: the maximum scale used to cut bridges. A certain maximum scale\
            cuts bridges up to a width (in voxels) of 2x the provided scale.\
            (Default: 2).
        axes: specify which axes should be included in the connected\
            components. By default only the first 3 axes are included. The axes\
            should be provided as a comma-separated list of values.
        largest: only retain the largest connected component.
        connectivity: use 26-voxel-neighbourhood connectivity (Default: 6).
        npass: the number of times to repeatedly apply the filter.
        extent: specify the extent (width) of kernel size in voxels. This can\
            be specified either as a single value to be used for all axes, or as a\
            comma-separated list of the extent for each axis. The default is 3x3x3.
        strides: specify the strides of the output data in memory; either as a\
            comma-separated list of (signed) integers, or as a template image from\
            which the strides shall be extracted and used. The actual strides\
            produced will depend on whether the output image format can support it.
        info: display information messages.
        quiet: do not display information messages or progress status;\
            alternatively, this can be achieved by setting the MRTRIX_QUIET\
            environment variable to a non-empty string.
        debug: display debugging messages.
        force: force overwrite of output files (caution: using the same file as\
            input and output might cause unexpected behaviour).
        nthreads: use this number of threads in multi-threaded applications\
            (set to 0 to disable multi-threading).
        config: temporarily set the value of an MRtrix config file entry.
        help_: display this information page and exit.
        version: display version information and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MaskfilterOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MASKFILTER_METADATA)
    cargs = []
    cargs.append("maskfilter")
    if scale is not None:
        cargs.extend([
            "-scale",
            str(scale)
        ])
    if axes is not None:
        cargs.extend([
            "-axes",
            ",".join(map(str, axes))
        ])
    if largest:
        cargs.append("-largest")
    if connectivity:
        cargs.append("-connectivity")
    if npass is not None:
        cargs.extend([
            "-npass",
            str(npass)
        ])
    if extent is not None:
        cargs.extend([
            "-extent",
            ",".join(map(str, extent))
        ])
    if strides is not None:
        cargs.extend([
            "-strides",
            strides
        ])
    if info:
        cargs.append("-info")
    if quiet:
        cargs.append("-quiet")
    if debug:
        cargs.append("-debug")
    if force:
        cargs.append("-force")
    if nthreads is not None:
        cargs.extend([
            "-nthreads",
            str(nthreads)
        ])
    if config is not None:
        cargs.extend([a for c in [s.run(execution) for s in config] for a in c])
    if help_:
        cargs.append("-help")
    if version:
        cargs.append("-version")
    cargs.append(execution.input_file(input_))
    cargs.append(filter_)
    cargs.append(output)
    ret = MaskfilterOutputs(
        root=execution.output_file("."),
        output=execution.output_file(output),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MASKFILTER_METADATA",
    "MaskfilterConfig",
    "MaskfilterOutputs",
    "maskfilter",
]
