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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRFILTER_METADATA = Metadata(
    id="3bb2ab8375a99185acaeac0f9e608829bff091ac.boutiques",
    name="mrfilter",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


@dataclasses.dataclass
class MrfilterVariousString:
    obj: str
    """String object."""
    
    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(self.obj)
        return cargs


@dataclasses.dataclass
class MrfilterVariousFile:
    obj: InputPathType
    """File object."""
    
    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(execution.input_file(self.obj))
        return cargs


@dataclasses.dataclass
class MrfilterConfig:
    """
    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 MrfilterOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mrfilter(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """the output image."""
    maskout: OutputPathType | None
    """Output a refined mask based on a spatially coherent region with normal
    intensity range. """


def mrfilter(
    input_: InputPathType,
    filter_: str,
    output: str,
    axes: list[int] | None = None,
    inverse: bool = False,
    magnitude: bool = False,
    centre_zero: bool = False,
    stdev: list[float] | None = None,
    magnitude_: bool = False,
    scanner: bool = False,
    extent: list[int] | None = None,
    extent_: list[int] | None = None,
    stdev_: list[float] | None = None,
    fwhm: list[float] | None = None,
    extent_2: list[int] | None = None,
    zupper: float | None = None,
    zlower: float | None = None,
    bridge: int | None = None,
    maskin: InputPathType | None = None,
    maskout: str | None = None,
    strides: typing.Union[MrfilterVariousString, MrfilterVariousFile] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrfilterConfig] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> MrfilterOutputs:
    """
    Perform filtering operations on 3D / 4D MR images.
    
    The available filters are: fft, gradient, median, smooth, normalise, zclean.
    
    Each filter has its own unique set of optional parameters.
    
    For 4D images, each 3D volume is processed independently.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        input_: the input image.
        filter_: the type of filter to be applied.
        output: the output image.
        axes: the axes along which to apply the Fourier Transform. By default,\
            the transform is applied along the three spatial axes. Provide as a\
            comma-separate list of axis indices.
        inverse: apply the inverse FFT.
        magnitude: output a magnitude image rather than a complex-valued image.
        centre_zero: re-arrange the FFT results so that the zero-frequency\
            component appears in the centre of the image, rather than at the edges.
        stdev: the standard deviation of the Gaussian kernel used to smooth the\
            input image (in mm). The image is smoothed to reduced large spurious\
            gradients caused by noise. Use this option to override the default\
            stdev of 1 voxel. This can be specified either as a single value to be\
            used for all 3 axes, or as a comma-separated list of 3 values, one for\
            each axis.
        magnitude_: output the gradient magnitude, rather than the default\
            x,y,z components.
        scanner: define the gradient with respect to the scanner coordinate\
            frame of reference.
        extent: specify extent of median filtering neighbourhood in voxels.\
            This can be specified either as a single value to be used for all 3\
            axes, or as a comma-separated list of 3 values, one for each axis\
            (default: 3x3x3).
        extent_: specify extent of normalisation filtering neighbourhood in\
            voxels. This can be specified either as a single value to be used for\
            all 3 axes, or as a comma-separated list of 3 values, one for each axis\
            (default: 3x3x3).
        stdev_: apply Gaussian smoothing with the specified standard deviation.\
            The standard deviation is defined in mm (Default 1 voxel). This can be\
            specified either as a single value to be used for all axes, or as a\
            comma-separated list of the stdev for each axis.
        fwhm: apply Gaussian smoothing with the specified full-width half\
            maximum. The FWHM is defined in mm (Default 1 voxel * 2.3548). This can\
            be specified either as a single value to be used for all axes, or as a\
            comma-separated list of the FWHM for each axis.
        extent_2: 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 extent is\
            2 * ceil(2.5 * stdev / voxel_size) - 1.
        zupper: define high intensity outliers: default: 2.5.
        zlower: define low intensity outliers: default: 2.5.
        bridge: number of voxels to gap to fill holes in mask: default: 4.
        maskin: initial mask that defines the maximum spatial extent and the\
            region from which to smaple the intensity range.
        maskout: Output a refined mask based on a spatially coherent region\
            with normal intensity range.
        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 `MrfilterOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRFILTER_METADATA)
    cargs = []
    cargs.append("mrfilter")
    if axes is not None:
        cargs.extend([
            "-axes",
            *map(str, axes)
        ])
    if inverse:
        cargs.append("-inverse")
    if magnitude:
        cargs.append("-magnitude")
    if centre_zero:
        cargs.append("-centre_zero")
    if stdev is not None:
        cargs.extend([
            "-stdev",
            ",".join(map(str, stdev))
        ])
    if magnitude_:
        cargs.append("-magnitude")
    if scanner:
        cargs.append("-scanner")
    if extent is not None:
        cargs.extend([
            "-extent",
            ",".join(map(str, extent))
        ])
    if extent_ is not None:
        cargs.extend([
            "-extent",
            ",".join(map(str, extent_))
        ])
    if stdev_ is not None:
        cargs.extend([
            "-stdev",
            ",".join(map(str, stdev_))
        ])
    if fwhm is not None:
        cargs.extend([
            "-fwhm",
            ",".join(map(str, fwhm))
        ])
    if extent_2 is not None:
        cargs.extend([
            "-extent",
            ",".join(map(str, extent_2))
        ])
    if zupper is not None:
        cargs.extend([
            "-zupper",
            str(zupper)
        ])
    if zlower is not None:
        cargs.extend([
            "-zlower",
            str(zlower)
        ])
    if bridge is not None:
        cargs.extend([
            "-bridge",
            str(bridge)
        ])
    if maskin is not None:
        cargs.extend([
            "-maskin",
            execution.input_file(maskin)
        ])
    if maskout is not None:
        cargs.extend([
            "-maskout",
            maskout
        ])
    if strides is not None:
        cargs.extend([
            "-strides",
            *strides.run(execution)
        ])
    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 = MrfilterOutputs(
        root=execution.output_file("."),
        output=execution.output_file(output),
        maskout=execution.output_file(maskout) if (maskout is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRFILTER_METADATA",
    "MrfilterConfig",
    "MrfilterOutputs",
    "MrfilterVariousFile",
    "MrfilterVariousString",
    "mrfilter",
]
