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

import typing
import pathlib
from styxdefs import *

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


_MrfilterVariousStringParamsDictNoTag = typing.TypedDict('_MrfilterVariousStringParamsDictNoTag', {
    "obj": str,
})
MrfilterVariousStringParamsDictTagged = typing.TypedDict('MrfilterVariousStringParamsDictTagged', {
    "@type": typing.Literal["VariousString"],
    "obj": str,
})
MrfilterVariousStringParamsDict = _MrfilterVariousStringParamsDictNoTag | MrfilterVariousStringParamsDictTagged


_MrfilterVariousFileParamsDictNoTag = typing.TypedDict('_MrfilterVariousFileParamsDictNoTag', {
    "obj": InputPathType,
})
MrfilterVariousFileParamsDictTagged = typing.TypedDict('MrfilterVariousFileParamsDictTagged', {
    "@type": typing.Literal["VariousFile"],
    "obj": InputPathType,
})
MrfilterVariousFileParamsDict = _MrfilterVariousFileParamsDictNoTag | MrfilterVariousFileParamsDictTagged


_MrfilterConfigParamsDictNoTag = typing.TypedDict('_MrfilterConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
MrfilterConfigParamsDictTagged = typing.TypedDict('MrfilterConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
MrfilterConfigParamsDict = _MrfilterConfigParamsDictNoTag | MrfilterConfigParamsDictTagged


_MrfilterParamsDictNoTag = typing.TypedDict('_MrfilterParamsDictNoTag', {
    "axes": typing.NotRequired[list[int] | None],
    "inverse": bool,
    "magnitude": bool,
    "centre_zero": bool,
    "stdev": typing.NotRequired[list[float] | None],
    "magnitude_1": bool,
    "scanner": bool,
    "extent": typing.NotRequired[list[int] | None],
    "extent_1": typing.NotRequired[list[int] | None],
    "stdev_1": typing.NotRequired[list[float] | None],
    "fwhm": typing.NotRequired[list[float] | None],
    "extent_2": typing.NotRequired[list[int] | None],
    "zupper": typing.NotRequired[float | None],
    "zlower": typing.NotRequired[float | None],
    "bridge": typing.NotRequired[int | None],
    "maskin": typing.NotRequired[InputPathType | None],
    "maskout": typing.NotRequired[str | None],
    "strides": typing.NotRequired[typing.Union[MrfilterVariousStringParamsDictTagged, MrfilterVariousFileParamsDictTagged] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MrfilterConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "filter": str,
    "output": str,
})
MrfilterParamsDictTagged = typing.TypedDict('MrfilterParamsDictTagged', {
    "@type": typing.Literal["mrtrix/mrfilter"],
    "axes": typing.NotRequired[list[int] | None],
    "inverse": bool,
    "magnitude": bool,
    "centre_zero": bool,
    "stdev": typing.NotRequired[list[float] | None],
    "magnitude_1": bool,
    "scanner": bool,
    "extent": typing.NotRequired[list[int] | None],
    "extent_1": typing.NotRequired[list[int] | None],
    "stdev_1": typing.NotRequired[list[float] | None],
    "fwhm": typing.NotRequired[list[float] | None],
    "extent_2": typing.NotRequired[list[int] | None],
    "zupper": typing.NotRequired[float | None],
    "zlower": typing.NotRequired[float | None],
    "bridge": typing.NotRequired[int | None],
    "maskin": typing.NotRequired[InputPathType | None],
    "maskout": typing.NotRequired[str | None],
    "strides": typing.NotRequired[typing.Union[MrfilterVariousStringParamsDictTagged, MrfilterVariousFileParamsDictTagged] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MrfilterConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "filter": str,
    "output": str,
})
MrfilterParamsDict = _MrfilterParamsDictNoTag | MrfilterParamsDictTagged


def mrfilter_strides_cargs_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "VariousString": mrfilter_various_string_cargs,
        "VariousFile": mrfilter_various_file_cargs,
    }.get(t)


def mrfilter_strides_validate_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get validate params function by command type.
    
    Args:
        t: Command type.
    Returns:
        Validate params function.
    """
    return {
        "VariousString": mrfilter_various_string_validate,
        "VariousFile": mrfilter_various_file_validate,
    }.get(t)


def mrfilter_various_string(
    obj: str,
) -> MrfilterVariousStringParamsDictTagged:
    """
    Build parameters.
    
    Args:
        obj: String object.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "VariousString",
        "obj": obj,
    }
    return params


def mrfilter_various_string_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrfilterVariousStringParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("obj", None) is None:
        raise StyxValidationError("`obj` must not be None")
    if not isinstance(params["obj"], str):
        raise StyxValidationError(f'`obj` has the wrong type: Received `{type(params.get("obj", None))}` expected `str`')


def mrfilter_various_string_cargs(
    params: MrfilterVariousStringParamsDict,
    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(params.get("obj", None))
    return cargs


def mrfilter_various_file(
    obj: InputPathType,
) -> MrfilterVariousFileParamsDictTagged:
    """
    Build parameters.
    
    Args:
        obj: File object.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "VariousFile",
        "obj": obj,
    }
    return params


def mrfilter_various_file_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrfilterVariousFileParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("obj", None) is None:
        raise StyxValidationError("`obj` must not be None")
    if not isinstance(params["obj"], (pathlib.Path, str)):
        raise StyxValidationError(f'`obj` has the wrong type: Received `{type(params.get("obj", None))}` expected `InputPathType`')


def mrfilter_various_file_cargs(
    params: MrfilterVariousFileParamsDict,
    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(execution.input_file(params.get("obj", None)))
    return cargs


def mrfilter_config(
    key: str,
    value: str,
) -> MrfilterConfigParamsDictTagged:
    """
    Build parameters.
    
    Args:
        key: temporarily set the value of an MRtrix config file entry.
        value: temporarily set the value of an MRtrix config file entry.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "config",
        "key": key,
        "value": value,
    }
    return params


def mrfilter_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrfilterConfigParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("key", None) is None:
        raise StyxValidationError("`key` must not be None")
    if not isinstance(params["key"], str):
        raise StyxValidationError(f'`key` has the wrong type: Received `{type(params.get("key", None))}` expected `str`')
    if params.get("value", None) is None:
        raise StyxValidationError("`value` must not be None")
    if not isinstance(params["value"], str):
        raise StyxValidationError(f'`value` has the wrong type: Received `{type(params.get("value", None))}` expected `str`')


def mrfilter_config_cargs(
    params: MrfilterConfigParamsDict,
    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("-config")
    cargs.append(params.get("key", None))
    cargs.append(params.get("value", None))
    return cargs


class MrfilterOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MrfilterParamsDict(...)`.
    """
    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_params(
    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_1: bool = False,
    scanner: bool = False,
    extent: list[int] | None = None,
    extent_1: list[int] | None = None,
    stdev_1: 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[MrfilterVariousStringParamsDictTagged, MrfilterVariousFileParamsDictTagged] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrfilterConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> MrfilterParamsDictTagged:
    """
    Build parameters.
    
    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_1: 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_1: 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_1: 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.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "mrtrix/mrfilter",
        "inverse": inverse,
        "magnitude": magnitude,
        "centre_zero": centre_zero,
        "magnitude_1": magnitude_1,
        "scanner": scanner,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "input": input_,
        "filter": filter_,
        "output": output,
    }
    if axes is not None:
        params["axes"] = axes
    if stdev is not None:
        params["stdev"] = stdev
    if extent is not None:
        params["extent"] = extent
    if extent_1 is not None:
        params["extent_1"] = extent_1
    if stdev_1 is not None:
        params["stdev_1"] = stdev_1
    if fwhm is not None:
        params["fwhm"] = fwhm
    if extent_2 is not None:
        params["extent_2"] = extent_2
    if zupper is not None:
        params["zupper"] = zupper
    if zlower is not None:
        params["zlower"] = zlower
    if bridge is not None:
        params["bridge"] = bridge
    if maskin is not None:
        params["maskin"] = maskin
    if maskout is not None:
        params["maskout"] = maskout
    if strides is not None:
        params["strides"] = strides
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def mrfilter_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrfilterParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("axes", None) is not None:
        if not isinstance(params["axes"], list):
            raise StyxValidationError(f'`axes` has the wrong type: Received `{type(params.get("axes", None))}` expected `list[int] | None`')
        for e in params["axes"]:
            if not isinstance(e, int):
                raise StyxValidationError(f'`axes` has the wrong type: Received `{type(params.get("axes", None))}` expected `list[int] | None`')
    if params.get("inverse", False) is None:
        raise StyxValidationError("`inverse` must not be None")
    if not isinstance(params["inverse"], bool):
        raise StyxValidationError(f'`inverse` has the wrong type: Received `{type(params.get("inverse", False))}` expected `bool`')
    if params.get("magnitude", False) is None:
        raise StyxValidationError("`magnitude` must not be None")
    if not isinstance(params["magnitude"], bool):
        raise StyxValidationError(f'`magnitude` has the wrong type: Received `{type(params.get("magnitude", False))}` expected `bool`')
    if params.get("centre_zero", False) is None:
        raise StyxValidationError("`centre_zero` must not be None")
    if not isinstance(params["centre_zero"], bool):
        raise StyxValidationError(f'`centre_zero` has the wrong type: Received `{type(params.get("centre_zero", False))}` expected `bool`')
    if params.get("stdev", None) is not None:
        if not isinstance(params["stdev"], list):
            raise StyxValidationError(f'`stdev` has the wrong type: Received `{type(params.get("stdev", None))}` expected `list[float] | None`')
        for e in params["stdev"]:
            if not isinstance(e, (float, int)):
                raise StyxValidationError(f'`stdev` has the wrong type: Received `{type(params.get("stdev", None))}` expected `list[float] | None`')
    if params.get("magnitude_1", False) is None:
        raise StyxValidationError("`magnitude_1` must not be None")
    if not isinstance(params["magnitude_1"], bool):
        raise StyxValidationError(f'`magnitude_1` has the wrong type: Received `{type(params.get("magnitude_1", False))}` expected `bool`')
    if params.get("scanner", False) is None:
        raise StyxValidationError("`scanner` must not be None")
    if not isinstance(params["scanner"], bool):
        raise StyxValidationError(f'`scanner` has the wrong type: Received `{type(params.get("scanner", False))}` expected `bool`')
    if params.get("extent", None) is not None:
        if not isinstance(params["extent"], list):
            raise StyxValidationError(f'`extent` has the wrong type: Received `{type(params.get("extent", None))}` expected `list[int] | None`')
        for e in params["extent"]:
            if not isinstance(e, int):
                raise StyxValidationError(f'`extent` has the wrong type: Received `{type(params.get("extent", None))}` expected `list[int] | None`')
    if params.get("extent_1", None) is not None:
        if not isinstance(params["extent_1"], list):
            raise StyxValidationError(f'`extent_1` has the wrong type: Received `{type(params.get("extent_1", None))}` expected `list[int] | None`')
        for e in params["extent_1"]:
            if not isinstance(e, int):
                raise StyxValidationError(f'`extent_1` has the wrong type: Received `{type(params.get("extent_1", None))}` expected `list[int] | None`')
    if params.get("stdev_1", None) is not None:
        if not isinstance(params["stdev_1"], list):
            raise StyxValidationError(f'`stdev_1` has the wrong type: Received `{type(params.get("stdev_1", None))}` expected `list[float] | None`')
        for e in params["stdev_1"]:
            if not isinstance(e, (float, int)):
                raise StyxValidationError(f'`stdev_1` has the wrong type: Received `{type(params.get("stdev_1", None))}` expected `list[float] | None`')
    if params.get("fwhm", None) is not None:
        if not isinstance(params["fwhm"], list):
            raise StyxValidationError(f'`fwhm` has the wrong type: Received `{type(params.get("fwhm", None))}` expected `list[float] | None`')
        for e in params["fwhm"]:
            if not isinstance(e, (float, int)):
                raise StyxValidationError(f'`fwhm` has the wrong type: Received `{type(params.get("fwhm", None))}` expected `list[float] | None`')
    if params.get("extent_2", None) is not None:
        if not isinstance(params["extent_2"], list):
            raise StyxValidationError(f'`extent_2` has the wrong type: Received `{type(params.get("extent_2", None))}` expected `list[int] | None`')
        for e in params["extent_2"]:
            if not isinstance(e, int):
                raise StyxValidationError(f'`extent_2` has the wrong type: Received `{type(params.get("extent_2", None))}` expected `list[int] | None`')
    if params.get("zupper", None) is not None:
        if not isinstance(params["zupper"], (float, int)):
            raise StyxValidationError(f'`zupper` has the wrong type: Received `{type(params.get("zupper", None))}` expected `float | None`')
    if params.get("zlower", None) is not None:
        if not isinstance(params["zlower"], (float, int)):
            raise StyxValidationError(f'`zlower` has the wrong type: Received `{type(params.get("zlower", None))}` expected `float | None`')
    if params.get("bridge", None) is not None:
        if not isinstance(params["bridge"], int):
            raise StyxValidationError(f'`bridge` has the wrong type: Received `{type(params.get("bridge", None))}` expected `int | None`')
    if params.get("maskin", None) is not None:
        if not isinstance(params["maskin"], (pathlib.Path, str)):
            raise StyxValidationError(f'`maskin` has the wrong type: Received `{type(params.get("maskin", None))}` expected `InputPathType | None`')
    if params.get("maskout", None) is not None:
        if not isinstance(params["maskout"], str):
            raise StyxValidationError(f'`maskout` has the wrong type: Received `{type(params.get("maskout", None))}` expected `str | None`')
    if params.get("strides", None) is not None:
        if not isinstance(params["strides"], dict):
            raise StyxValidationError(f'Params object has the wrong type \'{type(params["strides"])}\'')
        if "@type" not in params["strides"]:
            raise StyxValidationError("Params object is missing `@type`")
        if params["strides"]["@type"] not in ["VariousString", "VariousFile"]:
            raise StyxValidationError("Parameter `strides`s `@type` must be one of [\"VariousString\", \"VariousFile\"]")
        mrfilter_strides_validate_dyn_fn(params["strides"]["@type"])(params["strides"])
    if params.get("info", False) is None:
        raise StyxValidationError("`info` must not be None")
    if not isinstance(params["info"], bool):
        raise StyxValidationError(f'`info` has the wrong type: Received `{type(params.get("info", False))}` expected `bool`')
    if params.get("quiet", False) is None:
        raise StyxValidationError("`quiet` must not be None")
    if not isinstance(params["quiet"], bool):
        raise StyxValidationError(f'`quiet` has the wrong type: Received `{type(params.get("quiet", False))}` expected `bool`')
    if params.get("debug", False) is None:
        raise StyxValidationError("`debug` must not be None")
    if not isinstance(params["debug"], bool):
        raise StyxValidationError(f'`debug` has the wrong type: Received `{type(params.get("debug", False))}` expected `bool`')
    if params.get("force", False) is None:
        raise StyxValidationError("`force` must not be None")
    if not isinstance(params["force"], bool):
        raise StyxValidationError(f'`force` has the wrong type: Received `{type(params.get("force", False))}` expected `bool`')
    if params.get("nthreads", None) is not None:
        if not isinstance(params["nthreads"], int):
            raise StyxValidationError(f'`nthreads` has the wrong type: Received `{type(params.get("nthreads", None))}` expected `int | None`')
    if params.get("config", None) is not None:
        if not isinstance(params["config"], list):
            raise StyxValidationError(f'`config` has the wrong type: Received `{type(params.get("config", None))}` expected `list[MrfilterConfigParamsDict] | None`')
        for e in params["config"]:
            mrfilter_config_validate(e)
    if params.get("help", False) is None:
        raise StyxValidationError("`help` must not be None")
    if not isinstance(params["help"], bool):
        raise StyxValidationError(f'`help` has the wrong type: Received `{type(params.get("help", False))}` expected `bool`')
    if params.get("version", False) is None:
        raise StyxValidationError("`version` must not be None")
    if not isinstance(params["version"], bool):
        raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", False))}` expected `bool`')
    if params.get("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `InputPathType`')
    if params.get("filter", None) is None:
        raise StyxValidationError("`filter` must not be None")
    if not isinstance(params["filter"], str):
        raise StyxValidationError(f'`filter` has the wrong type: Received `{type(params.get("filter", None))}` expected `str`')
    if params.get("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')


def mrfilter_cargs(
    params: MrfilterParamsDict,
    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("mrfilter")
    if params.get("axes", None) is not None:
        cargs.extend([
            "-axes",
            *map(str, params.get("axes", None))
        ])
    if params.get("inverse", False):
        cargs.append("-inverse")
    if params.get("magnitude", False):
        cargs.append("-magnitude")
    if params.get("centre_zero", False):
        cargs.append("-centre_zero")
    if params.get("stdev", None) is not None:
        cargs.extend([
            "-stdev",
            ",".join(map(str, params.get("stdev", None)))
        ])
    if params.get("magnitude_1", False):
        cargs.append("-magnitude")
    if params.get("scanner", False):
        cargs.append("-scanner")
    if params.get("extent", None) is not None:
        cargs.extend([
            "-extent",
            ",".join(map(str, params.get("extent", None)))
        ])
    if params.get("extent_1", None) is not None:
        cargs.extend([
            "-extent",
            ",".join(map(str, params.get("extent_1", None)))
        ])
    if params.get("stdev_1", None) is not None:
        cargs.extend([
            "-stdev",
            ",".join(map(str, params.get("stdev_1", None)))
        ])
    if params.get("fwhm", None) is not None:
        cargs.extend([
            "-fwhm",
            ",".join(map(str, params.get("fwhm", None)))
        ])
    if params.get("extent_2", None) is not None:
        cargs.extend([
            "-extent",
            ",".join(map(str, params.get("extent_2", None)))
        ])
    if params.get("zupper", None) is not None:
        cargs.extend([
            "-zupper",
            str(params.get("zupper", None))
        ])
    if params.get("zlower", None) is not None:
        cargs.extend([
            "-zlower",
            str(params.get("zlower", None))
        ])
    if params.get("bridge", None) is not None:
        cargs.extend([
            "-bridge",
            str(params.get("bridge", None))
        ])
    if params.get("maskin", None) is not None:
        cargs.extend([
            "-maskin",
            execution.input_file(params.get("maskin", None))
        ])
    if params.get("maskout", None) is not None:
        cargs.extend([
            "-maskout",
            params.get("maskout", None)
        ])
    if params.get("strides", None) is not None:
        cargs.extend([
            "-strides",
            *mrfilter_strides_cargs_dyn_fn(params.get("strides", None)["@type"])(params.get("strides", None), execution)
        ])
    if params.get("info", False):
        cargs.append("-info")
    if params.get("quiet", False):
        cargs.append("-quiet")
    if params.get("debug", False):
        cargs.append("-debug")
    if params.get("force", False):
        cargs.append("-force")
    if params.get("nthreads", None) is not None:
        cargs.extend([
            "-nthreads",
            str(params.get("nthreads", None))
        ])
    if params.get("config", None) is not None:
        cargs.extend([a for c in [mrfilter_config_cargs(s, execution) for s in params.get("config", None)] for a in c])
    if params.get("help", False):
        cargs.append("-help")
    if params.get("version", False):
        cargs.append("-version")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("filter", None))
    cargs.append(params.get("output", None))
    return cargs


def mrfilter_outputs(
    params: MrfilterParamsDict,
    execution: Execution,
) -> MrfilterOutputs:
    """
    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 = MrfilterOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
        maskout=execution.output_file(params.get("maskout", None)) if (params.get("maskout") is not None) else None,
    )
    return ret


def mrfilter_execute(
    params: MrfilterParamsDict,
    runner: Runner | None = None,
) -> MrfilterOutputs:
    """
    mrfilter
    
    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:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MrfilterOutputs`).
    """
    mrfilter_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRFILTER_METADATA)
    params = execution.params(params)
    cargs = mrfilter_cargs(params, execution)
    ret = mrfilter_outputs(params, execution)
    execution.run(cargs)
    return ret


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_1: bool = False,
    scanner: bool = False,
    extent: list[int] | None = None,
    extent_1: list[int] | None = None,
    stdev_1: 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[MrfilterVariousStringParamsDictTagged, MrfilterVariousFileParamsDictTagged] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrfilterConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> MrfilterOutputs:
    """
    mrfilter
    
    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_1: 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_1: 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_1: 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`).
    """
    params = mrfilter_params(
        axes=axes,
        inverse=inverse,
        magnitude=magnitude,
        centre_zero=centre_zero,
        stdev=stdev,
        magnitude_1=magnitude_1,
        scanner=scanner,
        extent=extent,
        extent_1=extent_1,
        stdev_1=stdev_1,
        fwhm=fwhm,
        extent_2=extent_2,
        zupper=zupper,
        zlower=zlower,
        bridge=bridge,
        maskin=maskin,
        maskout=maskout,
        strides=strides,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        input_=input_,
        filter_=filter_,
        output=output,
    )
    return mrfilter_execute(params, runner)


__all__ = [
    "MRFILTER_METADATA",
    "MrfilterConfigParamsDict",
    "MrfilterConfigParamsDictTagged",
    "MrfilterOutputs",
    "MrfilterParamsDict",
    "MrfilterParamsDictTagged",
    "MrfilterVariousFileParamsDict",
    "MrfilterVariousFileParamsDictTagged",
    "MrfilterVariousStringParamsDict",
    "MrfilterVariousStringParamsDictTagged",
    "mrfilter",
    "mrfilter_config",
    "mrfilter_execute",
    "mrfilter_params",
    "mrfilter_various_file",
    "mrfilter_various_string",
]
