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

import typing
import pathlib
from styxdefs import *

FOD2DEC_METADATA = Metadata(
    id="56fd41eb31bb1240fd6341ac5abf21815b0e9dac.boutiques",
    name="fod2dec",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_Fod2decConfigParamsDictNoTag = typing.TypedDict('_Fod2decConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
Fod2decConfigParamsDictTagged = typing.TypedDict('Fod2decConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
Fod2decConfigParamsDict = _Fod2decConfigParamsDictNoTag | Fod2decConfigParamsDictTagged


_Fod2decParamsDictNoTag = typing.TypedDict('_Fod2decParamsDictNoTag', {
    "mask": typing.NotRequired[InputPathType | None],
    "contrast": typing.NotRequired[InputPathType | None],
    "lum": bool,
    "lum_coefs": typing.NotRequired[list[float] | None],
    "lum_gamma": typing.NotRequired[float | None],
    "threshold": typing.NotRequired[float | None],
    "no_weight": bool,
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Fod2decConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "output": str,
})
Fod2decParamsDictTagged = typing.TypedDict('Fod2decParamsDictTagged', {
    "@type": typing.Literal["mrtrix/fod2dec"],
    "mask": typing.NotRequired[InputPathType | None],
    "contrast": typing.NotRequired[InputPathType | None],
    "lum": bool,
    "lum_coefs": typing.NotRequired[list[float] | None],
    "lum_gamma": typing.NotRequired[float | None],
    "threshold": typing.NotRequired[float | None],
    "no_weight": bool,
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Fod2decConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "output": str,
})
Fod2decParamsDict = _Fod2decParamsDictNoTag | Fod2decParamsDictTagged


def fod2dec_config(
    key: str,
    value: str,
) -> Fod2decConfigParamsDictTagged:
    """
    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 fod2dec_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Fod2decConfigParamsDict` 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 fod2dec_config_cargs(
    params: Fod2decConfigParamsDict,
    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 Fod2decOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Fod2decParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output DEC image (weighted RGB triplets)."""


def fod2dec_params(
    input_: InputPathType,
    output: str,
    mask: InputPathType | None = None,
    contrast: InputPathType | None = None,
    lum: bool = False,
    lum_coefs: list[float] | None = None,
    lum_gamma: float | None = None,
    threshold: float | None = None,
    no_weight: bool = False,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Fod2decConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> Fod2decParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input FOD image (spherical harmonic coefficients).
        output: The output DEC image (weighted RGB triplets).
        mask: Only perform DEC computation within the specified mask image.
        contrast: Weight the computed DEC map by the provided image contrast.\
            If the contrast has a different image grid, the DEC map is first\
            resliced and renormalised. To achieve panchromatic sharpening, provide\
            an image with a higher spatial resolution than the input FOD image;\
            e.g., a T1 anatomical volume. Only the DEC is subject to the mask, so\
            as to allow for partial colouring of the contrast image.\
            Default when this option is *not* provided: integral of input FOD,\
            subject to the same mask/threshold as used for DEC computation.
        lum: Correct for luminance/perception, using default values Cr,Cg,Cb =\
            0.3,0.5,0.2 and gamma = 2.2 (*not* correcting is the theoretical\
            equivalent of Cr,Cg,Cb = 1,1,1 and gamma = 2).
        lum_coefs: The coefficients Cr,Cg,Cb to correct for\
            luminance/perception.\
            Note: this implicitly switches on luminance/perception correction,\
            using a default gamma = 2.2 unless specified otherwise.
        lum_gamma: The gamma value to correct for luminance/perception.\
            Note: this implicitly switches on luminance/perception correction,\
            using a default Cr,Cg,Cb = 0.3,0.5,0.2 unless specified otherwise.
        threshold: FOD amplitudes below the threshold value are considered\
            zero.
        no_weight: Do not weight the DEC map; just output the unweighted\
            colours. Reslicing and renormalising of colours will still happen when\
            providing the -contrast option as a template.
        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/fod2dec",
        "lum": lum,
        "no_weight": no_weight,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "input": input_,
        "output": output,
    }
    if mask is not None:
        params["mask"] = mask
    if contrast is not None:
        params["contrast"] = contrast
    if lum_coefs is not None:
        params["lum_coefs"] = lum_coefs
    if lum_gamma is not None:
        params["lum_gamma"] = lum_gamma
    if threshold is not None:
        params["threshold"] = threshold
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def fod2dec_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Fod2decParamsDict` 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("mask", None) is not None:
        if not isinstance(params["mask"], (pathlib.Path, str)):
            raise StyxValidationError(f'`mask` has the wrong type: Received `{type(params.get("mask", None))}` expected `InputPathType | None`')
    if params.get("contrast", None) is not None:
        if not isinstance(params["contrast"], (pathlib.Path, str)):
            raise StyxValidationError(f'`contrast` has the wrong type: Received `{type(params.get("contrast", None))}` expected `InputPathType | None`')
    if params.get("lum", False) is None:
        raise StyxValidationError("`lum` must not be None")
    if not isinstance(params["lum"], bool):
        raise StyxValidationError(f'`lum` has the wrong type: Received `{type(params.get("lum", False))}` expected `bool`')
    if params.get("lum_coefs", None) is not None:
        if not isinstance(params["lum_coefs"], list):
            raise StyxValidationError(f'`lum_coefs` has the wrong type: Received `{type(params.get("lum_coefs", None))}` expected `list[float] | None`')
        for e in params["lum_coefs"]:
            if not isinstance(e, (float, int)):
                raise StyxValidationError(f'`lum_coefs` has the wrong type: Received `{type(params.get("lum_coefs", None))}` expected `list[float] | None`')
    if params.get("lum_gamma", None) is not None:
        if not isinstance(params["lum_gamma"], (float, int)):
            raise StyxValidationError(f'`lum_gamma` has the wrong type: Received `{type(params.get("lum_gamma", None))}` expected `float | None`')
    if params.get("threshold", None) is not None:
        if not isinstance(params["threshold"], (float, int)):
            raise StyxValidationError(f'`threshold` has the wrong type: Received `{type(params.get("threshold", None))}` expected `float | None`')
    if params.get("no_weight", False) is None:
        raise StyxValidationError("`no_weight` must not be None")
    if not isinstance(params["no_weight"], bool):
        raise StyxValidationError(f'`no_weight` has the wrong type: Received `{type(params.get("no_weight", False))}` expected `bool`')
    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[Fod2decConfigParamsDict] | None`')
        for e in params["config"]:
            fod2dec_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("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 fod2dec_cargs(
    params: Fod2decParamsDict,
    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("fod2dec")
    if params.get("mask", None) is not None:
        cargs.extend([
            "-mask",
            execution.input_file(params.get("mask", None))
        ])
    if params.get("contrast", None) is not None:
        cargs.extend([
            "-contrast",
            execution.input_file(params.get("contrast", None))
        ])
    if params.get("lum", False):
        cargs.append("-lum")
    if params.get("lum_coefs", None) is not None:
        cargs.extend([
            "-lum_coefs",
            *map(str, params.get("lum_coefs", None))
        ])
    if params.get("lum_gamma", None) is not None:
        cargs.extend([
            "-lum_gamma",
            str(params.get("lum_gamma", None))
        ])
    if params.get("threshold", None) is not None:
        cargs.extend([
            "-threshold",
            str(params.get("threshold", None))
        ])
    if params.get("no_weight", False):
        cargs.append("-no_weight")
    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 [fod2dec_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("output", None))
    return cargs


def fod2dec_outputs(
    params: Fod2decParamsDict,
    execution: Execution,
) -> Fod2decOutputs:
    """
    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 = Fod2decOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
    )
    return ret


def fod2dec_execute(
    params: Fod2decParamsDict,
    runner: Runner | None = None,
) -> Fod2decOutputs:
    """
    fod2dec
    
    Generate FOD-based DEC maps, with optional panchromatic sharpening and/or
    luminance/perception correction.
    
    By default, the FOD-based DEC is weighted by the integral of the FOD. To
    weight by another scalar map, use the -contrast option. This option can also
    be used for panchromatic sharpening, e.g., by supplying a T1 (or other
    sensible) anatomical volume with a higher spatial resolution.
    
    References:
    
    Dhollander T, Smith RE, Tournier JD, Jeurissen B, Connelly A. Time to move
    on: an FOD-based DEC map to replace DTI's trademark DEC FA. Proc Intl Soc
    Mag Reson Med, 2015, 23, 1027
    
    Dhollander T, Raffelt D, Smith RE, Connelly A. Panchromatic sharpening of
    FOD-based DEC maps by structural T1 information. Proc Intl Soc Mag Reson
    Med, 2015, 23, 566.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Fod2decOutputs`).
    """
    fod2dec_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(FOD2DEC_METADATA)
    params = execution.params(params)
    cargs = fod2dec_cargs(params, execution)
    ret = fod2dec_outputs(params, execution)
    execution.run(cargs)
    return ret


def fod2dec(
    input_: InputPathType,
    output: str,
    mask: InputPathType | None = None,
    contrast: InputPathType | None = None,
    lum: bool = False,
    lum_coefs: list[float] | None = None,
    lum_gamma: float | None = None,
    threshold: float | None = None,
    no_weight: bool = False,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Fod2decConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> Fod2decOutputs:
    """
    fod2dec
    
    Generate FOD-based DEC maps, with optional panchromatic sharpening and/or
    luminance/perception correction.
    
    By default, the FOD-based DEC is weighted by the integral of the FOD. To
    weight by another scalar map, use the -contrast option. This option can also
    be used for panchromatic sharpening, e.g., by supplying a T1 (or other
    sensible) anatomical volume with a higher spatial resolution.
    
    References:
    
    Dhollander T, Smith RE, Tournier JD, Jeurissen B, Connelly A. Time to move
    on: an FOD-based DEC map to replace DTI's trademark DEC FA. Proc Intl Soc
    Mag Reson Med, 2015, 23, 1027
    
    Dhollander T, Raffelt D, Smith RE, Connelly A. Panchromatic sharpening of
    FOD-based DEC maps by structural T1 information. Proc Intl Soc Mag Reson
    Med, 2015, 23, 566.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        input_: The input FOD image (spherical harmonic coefficients).
        output: The output DEC image (weighted RGB triplets).
        mask: Only perform DEC computation within the specified mask image.
        contrast: Weight the computed DEC map by the provided image contrast.\
            If the contrast has a different image grid, the DEC map is first\
            resliced and renormalised. To achieve panchromatic sharpening, provide\
            an image with a higher spatial resolution than the input FOD image;\
            e.g., a T1 anatomical volume. Only the DEC is subject to the mask, so\
            as to allow for partial colouring of the contrast image.\
            Default when this option is *not* provided: integral of input FOD,\
            subject to the same mask/threshold as used for DEC computation.
        lum: Correct for luminance/perception, using default values Cr,Cg,Cb =\
            0.3,0.5,0.2 and gamma = 2.2 (*not* correcting is the theoretical\
            equivalent of Cr,Cg,Cb = 1,1,1 and gamma = 2).
        lum_coefs: The coefficients Cr,Cg,Cb to correct for\
            luminance/perception.\
            Note: this implicitly switches on luminance/perception correction,\
            using a default gamma = 2.2 unless specified otherwise.
        lum_gamma: The gamma value to correct for luminance/perception.\
            Note: this implicitly switches on luminance/perception correction,\
            using a default Cr,Cg,Cb = 0.3,0.5,0.2 unless specified otherwise.
        threshold: FOD amplitudes below the threshold value are considered\
            zero.
        no_weight: Do not weight the DEC map; just output the unweighted\
            colours. Reslicing and renormalising of colours will still happen when\
            providing the -contrast option as a template.
        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 `Fod2decOutputs`).
    """
    params = fod2dec_params(
        mask=mask,
        contrast=contrast,
        lum=lum,
        lum_coefs=lum_coefs,
        lum_gamma=lum_gamma,
        threshold=threshold,
        no_weight=no_weight,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        input_=input_,
        output=output,
    )
    return fod2dec_execute(params, runner)


__all__ = [
    "FOD2DEC_METADATA",
    "Fod2decConfigParamsDict",
    "Fod2decConfigParamsDictTagged",
    "Fod2decOutputs",
    "Fod2decParamsDict",
    "Fod2decParamsDictTagged",
    "fod2dec",
    "fod2dec_config",
    "fod2dec_execute",
    "fod2dec_params",
]
