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

import typing
import pathlib
from styxdefs import *

MRDEGIBBS_METADATA = Metadata(
    id="832d935b5fa8fdff97b78ecd355cb0d26be8033a.boutiques",
    name="mrdegibbs",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_MrdegibbsConfigParamsDictNoTag = typing.TypedDict('_MrdegibbsConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
MrdegibbsConfigParamsDictTagged = typing.TypedDict('MrdegibbsConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
MrdegibbsConfigParamsDict = _MrdegibbsConfigParamsDictNoTag | MrdegibbsConfigParamsDictTagged


_MrdegibbsParamsDictNoTag = typing.TypedDict('_MrdegibbsParamsDictNoTag', {
    "axes": typing.NotRequired[list[int] | None],
    "nshifts": typing.NotRequired[int | None],
    "minW": typing.NotRequired[int | None],
    "maxW": typing.NotRequired[int | None],
    "datatype": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MrdegibbsConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "in": InputPathType,
    "out": str,
})
MrdegibbsParamsDictTagged = typing.TypedDict('MrdegibbsParamsDictTagged', {
    "@type": typing.Literal["mrtrix/mrdegibbs"],
    "axes": typing.NotRequired[list[int] | None],
    "nshifts": typing.NotRequired[int | None],
    "minW": typing.NotRequired[int | None],
    "maxW": typing.NotRequired[int | None],
    "datatype": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MrdegibbsConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "in": InputPathType,
    "out": str,
})
MrdegibbsParamsDict = _MrdegibbsParamsDictNoTag | MrdegibbsParamsDictTagged


def mrdegibbs_config(
    key: str,
    value: str,
) -> MrdegibbsConfigParamsDictTagged:
    """
    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 mrdegibbs_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrdegibbsConfigParamsDict` 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 mrdegibbs_config_cargs(
    params: MrdegibbsConfigParamsDict,
    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 MrdegibbsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MrdegibbsParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out: OutputPathType
    """the output image."""


def mrdegibbs_params(
    in_: InputPathType,
    out: str,
    axes: list[int] | None = None,
    nshifts: int | None = None,
    min_w: int | None = None,
    max_w: int | None = None,
    datatype: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrdegibbsConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> MrdegibbsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        in_: the input image.
        out: the output image.
        axes: select the slice axes (default: 0,1 - i.e. x-y).
        nshifts: discretization of subpixel spacing (default: 20).
        min_w: left border of window used for TV computation (default: 1).
        max_w: right border of window used for TV computation (default: 3).
        datatype: specify output image data type. Valid choices are: float32,\
            float32le, float32be, float64, float64le, float64be, int64, uint64,\
            int64le, uint64le, int64be, uint64be, int32, uint32, int32le, uint32le,\
            int32be, uint32be, int16, uint16, int16le, uint16le, int16be, uint16be,\
            cfloat32, cfloat32le, cfloat32be, cfloat64, cfloat64le, cfloat64be,\
            int8, uint8, bit.
        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/mrdegibbs",
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "in": in_,
        "out": out,
    }
    if axes is not None:
        params["axes"] = axes
    if nshifts is not None:
        params["nshifts"] = nshifts
    if min_w is not None:
        params["minW"] = min_w
    if max_w is not None:
        params["maxW"] = max_w
    if datatype is not None:
        params["datatype"] = datatype
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def mrdegibbs_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrdegibbsParamsDict` 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("nshifts", None) is not None:
        if not isinstance(params["nshifts"], int):
            raise StyxValidationError(f'`nshifts` has the wrong type: Received `{type(params.get("nshifts", None))}` expected `int | None`')
    if params.get("minW", None) is not None:
        if not isinstance(params["minW"], int):
            raise StyxValidationError(f'`minW` has the wrong type: Received `{type(params.get("minW", None))}` expected `int | None`')
    if params.get("maxW", None) is not None:
        if not isinstance(params["maxW"], int):
            raise StyxValidationError(f'`maxW` has the wrong type: Received `{type(params.get("maxW", None))}` expected `int | None`')
    if params.get("datatype", None) is not None:
        if not isinstance(params["datatype"], str):
            raise StyxValidationError(f'`datatype` has the wrong type: Received `{type(params.get("datatype", None))}` expected `str | None`')
    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[MrdegibbsConfigParamsDict] | None`')
        for e in params["config"]:
            mrdegibbs_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("in", None) is None:
        raise StyxValidationError("`in` must not be None")
    if not isinstance(params["in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`in` has the wrong type: Received `{type(params.get("in", None))}` expected `InputPathType`')
    if params.get("out", None) is None:
        raise StyxValidationError("`out` must not be None")
    if not isinstance(params["out"], str):
        raise StyxValidationError(f'`out` has the wrong type: Received `{type(params.get("out", None))}` expected `str`')


def mrdegibbs_cargs(
    params: MrdegibbsParamsDict,
    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("mrdegibbs")
    if params.get("axes", None) is not None:
        cargs.extend([
            "-axes",
            *map(str, params.get("axes", None))
        ])
    if params.get("nshifts", None) is not None:
        cargs.extend([
            "-nshifts",
            str(params.get("nshifts", None))
        ])
    if params.get("minW", None) is not None:
        cargs.extend([
            "-minW",
            str(params.get("minW", None))
        ])
    if params.get("maxW", None) is not None:
        cargs.extend([
            "-maxW",
            str(params.get("maxW", None))
        ])
    if params.get("datatype", None) is not None:
        cargs.extend([
            "-datatype",
            params.get("datatype", None)
        ])
    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 [mrdegibbs_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("in", None)))
    cargs.append(params.get("out", None))
    return cargs


def mrdegibbs_outputs(
    params: MrdegibbsParamsDict,
    execution: Execution,
) -> MrdegibbsOutputs:
    """
    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 = MrdegibbsOutputs(
        root=execution.output_file("."),
        out=execution.output_file(params.get("out", None)),
    )
    return ret


def mrdegibbs_execute(
    params: MrdegibbsParamsDict,
    runner: Runner | None = None,
) -> MrdegibbsOutputs:
    """
    mrdegibbs
    
    Remove Gibbs Ringing Artifacts.
    
    This application attempts to remove Gibbs ringing artefacts from MRI images
    using the method of local subvoxel-shifts proposed by Kellner et al. (see
    reference below for details).
    
    This command is designed to run on data directly after it has been
    reconstructed by the scanner, before any interpolation of any kind has taken
    place. You should not run this command after any form of motion correction
    (e.g. not after dwifslpreproc). Similarly, if you intend running dwidenoise,
    you should run denoising before this command to not alter the noise
    structure, which would impact on dwidenoise's performance.
    
    Note that this method is designed to work on images acquired with full
    k-space coverage. Running this method on partial Fourier ('half-scan') data
    may lead to suboptimal and/or biased results, as noted in the original
    reference below. There is currently no means of dealing with this; users
    should exercise caution when using this method on partial Fourier data, and
    inspect its output for any obvious artefacts.
    
    References:
    
    Kellner, E; Dhital, B; Kiselev, V.G & Reisert, M. Gibbs-ringing artifact
    removal based on local subvoxel-shifts. Magnetic Resonance in Medicine,
    2016, 76, 1574â€“1581.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MrdegibbsOutputs`).
    """
    mrdegibbs_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRDEGIBBS_METADATA)
    params = execution.params(params)
    cargs = mrdegibbs_cargs(params, execution)
    ret = mrdegibbs_outputs(params, execution)
    execution.run(cargs)
    return ret


def mrdegibbs(
    in_: InputPathType,
    out: str,
    axes: list[int] | None = None,
    nshifts: int | None = None,
    min_w: int | None = None,
    max_w: int | None = None,
    datatype: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrdegibbsConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> MrdegibbsOutputs:
    """
    mrdegibbs
    
    Remove Gibbs Ringing Artifacts.
    
    This application attempts to remove Gibbs ringing artefacts from MRI images
    using the method of local subvoxel-shifts proposed by Kellner et al. (see
    reference below for details).
    
    This command is designed to run on data directly after it has been
    reconstructed by the scanner, before any interpolation of any kind has taken
    place. You should not run this command after any form of motion correction
    (e.g. not after dwifslpreproc). Similarly, if you intend running dwidenoise,
    you should run denoising before this command to not alter the noise
    structure, which would impact on dwidenoise's performance.
    
    Note that this method is designed to work on images acquired with full
    k-space coverage. Running this method on partial Fourier ('half-scan') data
    may lead to suboptimal and/or biased results, as noted in the original
    reference below. There is currently no means of dealing with this; users
    should exercise caution when using this method on partial Fourier data, and
    inspect its output for any obvious artefacts.
    
    References:
    
    Kellner, E; Dhital, B; Kiselev, V.G & Reisert, M. Gibbs-ringing artifact
    removal based on local subvoxel-shifts. Magnetic Resonance in Medicine,
    2016, 76, 1574â€“1581.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        in_: the input image.
        out: the output image.
        axes: select the slice axes (default: 0,1 - i.e. x-y).
        nshifts: discretization of subpixel spacing (default: 20).
        min_w: left border of window used for TV computation (default: 1).
        max_w: right border of window used for TV computation (default: 3).
        datatype: specify output image data type. Valid choices are: float32,\
            float32le, float32be, float64, float64le, float64be, int64, uint64,\
            int64le, uint64le, int64be, uint64be, int32, uint32, int32le, uint32le,\
            int32be, uint32be, int16, uint16, int16le, uint16le, int16be, uint16be,\
            cfloat32, cfloat32le, cfloat32be, cfloat64, cfloat64le, cfloat64be,\
            int8, uint8, bit.
        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 `MrdegibbsOutputs`).
    """
    params = mrdegibbs_params(
        axes=axes,
        nshifts=nshifts,
        min_w=min_w,
        max_w=max_w,
        datatype=datatype,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        in_=in_,
        out=out,
    )
    return mrdegibbs_execute(params, runner)


__all__ = [
    "MRDEGIBBS_METADATA",
    "MrdegibbsConfigParamsDict",
    "MrdegibbsConfigParamsDictTagged",
    "MrdegibbsOutputs",
    "MrdegibbsParamsDict",
    "MrdegibbsParamsDictTagged",
    "mrdegibbs",
    "mrdegibbs_config",
    "mrdegibbs_execute",
    "mrdegibbs_params",
]
