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

import typing
import pathlib
from styxdefs import *

DWI2FOD_METADATA = Metadata(
    id="6d16386fcfa6e4701ad68f4333de7173683fda45.boutiques",
    name="dwi2fod",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_Dwi2fodFslgradParamsDictNoTag = typing.TypedDict('_Dwi2fodFslgradParamsDictNoTag', {
    "bvecs": InputPathType,
    "bvals": InputPathType,
})
Dwi2fodFslgradParamsDictTagged = typing.TypedDict('Dwi2fodFslgradParamsDictTagged', {
    "@type": typing.Literal["fslgrad"],
    "bvecs": InputPathType,
    "bvals": InputPathType,
})
Dwi2fodFslgradParamsDict = _Dwi2fodFslgradParamsDictNoTag | Dwi2fodFslgradParamsDictTagged


_Dwi2fodVariousStringParamsDictNoTag = typing.TypedDict('_Dwi2fodVariousStringParamsDictNoTag', {
    "obj": str,
})
Dwi2fodVariousStringParamsDictTagged = typing.TypedDict('Dwi2fodVariousStringParamsDictTagged', {
    "@type": typing.Literal["VariousString"],
    "obj": str,
})
Dwi2fodVariousStringParamsDict = _Dwi2fodVariousStringParamsDictNoTag | Dwi2fodVariousStringParamsDictTagged


_Dwi2fodVariousFileParamsDictNoTag = typing.TypedDict('_Dwi2fodVariousFileParamsDictNoTag', {
    "obj": InputPathType,
})
Dwi2fodVariousFileParamsDictTagged = typing.TypedDict('Dwi2fodVariousFileParamsDictTagged', {
    "@type": typing.Literal["VariousFile"],
    "obj": InputPathType,
})
Dwi2fodVariousFileParamsDict = _Dwi2fodVariousFileParamsDictNoTag | Dwi2fodVariousFileParamsDictTagged


_Dwi2fodConfigParamsDictNoTag = typing.TypedDict('_Dwi2fodConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
Dwi2fodConfigParamsDictTagged = typing.TypedDict('Dwi2fodConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
Dwi2fodConfigParamsDict = _Dwi2fodConfigParamsDictNoTag | Dwi2fodConfigParamsDictTagged


_Dwi2fodResponseOdfParamsDictNoTag = typing.TypedDict('_Dwi2fodResponseOdfParamsDictNoTag', {
    "response": InputPathType,
    "odf": str,
})
Dwi2fodResponseOdfParamsDictTagged = typing.TypedDict('Dwi2fodResponseOdfParamsDictTagged', {
    "@type": typing.Literal["response_odf"],
    "response": InputPathType,
    "odf": str,
})
Dwi2fodResponseOdfParamsDict = _Dwi2fodResponseOdfParamsDictNoTag | Dwi2fodResponseOdfParamsDictTagged


_Dwi2fodParamsDictNoTag = typing.TypedDict('_Dwi2fodParamsDictNoTag', {
    "grad": typing.NotRequired[InputPathType | None],
    "fslgrad": typing.NotRequired[Dwi2fodFslgradParamsDict | None],
    "shells": typing.NotRequired[list[float] | None],
    "directions": typing.NotRequired[InputPathType | None],
    "lmax": typing.NotRequired[list[int] | None],
    "mask": typing.NotRequired[InputPathType | None],
    "filter": typing.NotRequired[InputPathType | None],
    "neg_lambda": typing.NotRequired[float | None],
    "norm_lambda": typing.NotRequired[float | None],
    "threshold": typing.NotRequired[float | None],
    "niter": typing.NotRequired[int | None],
    "norm_lambda_1": typing.NotRequired[float | None],
    "neg_lambda_1": typing.NotRequired[float | None],
    "predicted_signal": typing.NotRequired[str | None],
    "strides": typing.NotRequired[typing.Union[Dwi2fodVariousStringParamsDictTagged, Dwi2fodVariousFileParamsDictTagged] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Dwi2fodConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "algorithm": str,
    "dwi": InputPathType,
    "response_odf": list[Dwi2fodResponseOdfParamsDict],
})
Dwi2fodParamsDictTagged = typing.TypedDict('Dwi2fodParamsDictTagged', {
    "@type": typing.Literal["mrtrix/dwi2fod"],
    "grad": typing.NotRequired[InputPathType | None],
    "fslgrad": typing.NotRequired[Dwi2fodFslgradParamsDict | None],
    "shells": typing.NotRequired[list[float] | None],
    "directions": typing.NotRequired[InputPathType | None],
    "lmax": typing.NotRequired[list[int] | None],
    "mask": typing.NotRequired[InputPathType | None],
    "filter": typing.NotRequired[InputPathType | None],
    "neg_lambda": typing.NotRequired[float | None],
    "norm_lambda": typing.NotRequired[float | None],
    "threshold": typing.NotRequired[float | None],
    "niter": typing.NotRequired[int | None],
    "norm_lambda_1": typing.NotRequired[float | None],
    "neg_lambda_1": typing.NotRequired[float | None],
    "predicted_signal": typing.NotRequired[str | None],
    "strides": typing.NotRequired[typing.Union[Dwi2fodVariousStringParamsDictTagged, Dwi2fodVariousFileParamsDictTagged] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Dwi2fodConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "algorithm": str,
    "dwi": InputPathType,
    "response_odf": list[Dwi2fodResponseOdfParamsDict],
})
Dwi2fodParamsDict = _Dwi2fodParamsDictNoTag | Dwi2fodParamsDictTagged


def dwi2fod_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": dwi2fod_various_string_cargs,
        "VariousFile": dwi2fod_various_file_cargs,
    }.get(t)


def dwi2fod_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": dwi2fod_various_string_validate,
        "VariousFile": dwi2fod_various_file_validate,
    }.get(t)


def dwi2fod_fslgrad(
    bvecs: InputPathType,
    bvals: InputPathType,
) -> Dwi2fodFslgradParamsDictTagged:
    """
    Build parameters.
    
    Args:
        bvecs: Provide the diffusion-weighted gradient scheme used in the\
            acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
            scheme is present in the input image header, the data provided with\
            this option will be instead used.
        bvals: Provide the diffusion-weighted gradient scheme used in the\
            acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
            scheme is present in the input image header, the data provided with\
            this option will be instead used.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "fslgrad",
        "bvecs": bvecs,
        "bvals": bvals,
    }
    return params


def dwi2fod_fslgrad_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2fodFslgradParamsDict` 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("bvecs", None) is None:
        raise StyxValidationError("`bvecs` must not be None")
    if not isinstance(params["bvecs"], (pathlib.Path, str)):
        raise StyxValidationError(f'`bvecs` has the wrong type: Received `{type(params.get("bvecs", None))}` expected `InputPathType`')
    if params.get("bvals", None) is None:
        raise StyxValidationError("`bvals` must not be None")
    if not isinstance(params["bvals"], (pathlib.Path, str)):
        raise StyxValidationError(f'`bvals` has the wrong type: Received `{type(params.get("bvals", None))}` expected `InputPathType`')


def dwi2fod_fslgrad_cargs(
    params: Dwi2fodFslgradParamsDict,
    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("-fslgrad")
    cargs.append(execution.input_file(params.get("bvecs", None)))
    cargs.append(execution.input_file(params.get("bvals", None)))
    return cargs


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


def dwi2fod_various_string_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2fodVariousStringParamsDict` 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 dwi2fod_various_string_cargs(
    params: Dwi2fodVariousStringParamsDict,
    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 dwi2fod_various_file(
    obj: InputPathType,
) -> Dwi2fodVariousFileParamsDictTagged:
    """
    Build parameters.
    
    Args:
        obj: File object.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "VariousFile",
        "obj": obj,
    }
    return params


def dwi2fod_various_file_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2fodVariousFileParamsDict` 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 dwi2fod_various_file_cargs(
    params: Dwi2fodVariousFileParamsDict,
    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 dwi2fod_config(
    key: str,
    value: str,
) -> Dwi2fodConfigParamsDictTagged:
    """
    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 dwi2fod_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2fodConfigParamsDict` 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 dwi2fod_config_cargs(
    params: Dwi2fodConfigParamsDict,
    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 Dwi2fodResponseOdfOutputs(typing.NamedTuple):
    """
    Output object returned when calling `list[Dwi2fodResponseOdfParamsDict](...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    odf: OutputPathType
    """output ODF image"""


def dwi2fod_response_odf(
    response: InputPathType,
    odf: str,
) -> Dwi2fodResponseOdfParamsDictTagged:
    """
    Build parameters.
    
    Args:
        response: input tissue response.
        odf: output ODF image.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "response_odf",
        "response": response,
        "odf": odf,
    }
    return params


def dwi2fod_response_odf_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2fodResponseOdfParamsDict` 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("response", None) is None:
        raise StyxValidationError("`response` must not be None")
    if not isinstance(params["response"], (pathlib.Path, str)):
        raise StyxValidationError(f'`response` has the wrong type: Received `{type(params.get("response", None))}` expected `InputPathType`')
    if params.get("odf", None) is None:
        raise StyxValidationError("`odf` must not be None")
    if not isinstance(params["odf"], str):
        raise StyxValidationError(f'`odf` has the wrong type: Received `{type(params.get("odf", None))}` expected `str`')


def dwi2fod_response_odf_cargs(
    params: Dwi2fodResponseOdfParamsDict,
    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("response", None)))
    cargs.append(params.get("odf", None))
    return cargs


def dwi2fod_response_odf_outputs(
    params: Dwi2fodResponseOdfParamsDict,
    execution: Execution,
) -> Dwi2fodResponseOdfOutputs:
    """
    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 = Dwi2fodResponseOdfOutputs(
        root=execution.output_file("."),
        odf=execution.output_file(params.get("odf", None)),
    )
    return ret


class Dwi2fodOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Dwi2fodParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    predicted_signal: OutputPathType | None
    """output the predicted dwi image. """
    response_odf: list[Dwi2fodResponseOdfOutputs]
    """Outputs from `dwi2fod_response_odf_outputs`.This is a list of outputs
    with the same length and order as the inputs."""


def dwi2fod_params(
    algorithm: str,
    dwi: InputPathType,
    response_odf: list[Dwi2fodResponseOdfParamsDict],
    grad: InputPathType | None = None,
    fslgrad: Dwi2fodFslgradParamsDict | None = None,
    shells: list[float] | None = None,
    directions: InputPathType | None = None,
    lmax: list[int] | None = None,
    mask: InputPathType | None = None,
    filter_: InputPathType | None = None,
    neg_lambda: float | None = None,
    norm_lambda: float | None = None,
    threshold: float | None = None,
    niter: int | None = None,
    norm_lambda_1: float | None = None,
    neg_lambda_1: float | None = None,
    predicted_signal: str | None = None,
    strides: typing.Union[Dwi2fodVariousStringParamsDictTagged, Dwi2fodVariousFileParamsDictTagged] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Dwi2fodConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> Dwi2fodParamsDictTagged:
    """
    Build parameters.
    
    Args:
        algorithm: the algorithm to use for FOD estimation. (options are:\
            csd,msmt_csd).
        dwi: the input diffusion-weighted image.
        response_odf: pairs of input tissue response and output ODF images.
        grad: Provide the diffusion-weighted gradient scheme used in the\
            acquisition in a text file. This should be supplied as a 4xN text file\
            with each line is in the format [ X Y Z b ], where [ X Y Z ] describe\
            the direction of the applied gradient, and b gives the b-value in units\
            of s/mm^2. If a diffusion gradient scheme is present in the input image\
            header, the data provided with this option will be instead used.
        fslgrad: Provide the diffusion-weighted gradient scheme used in the\
            acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
            scheme is present in the input image header, the data provided with\
            this option will be instead used.
        shells: specify one or more b-values to use during processing, as a\
            comma-separated list of the desired approximate b-values (b-values are\
            clustered to allow for small deviations). Note that some commands are\
            incompatible with multiple b-values, and will report an error if more\
            than one b-value is provided.\
            WARNING: note that, even though the b=0 volumes are never referred\
            to as shells in the literature, they still have to be explicitly\
            included in the list of b-values as provided to the -shell option!\
            Several algorithms which include the b=0 volumes in their\
            computations may otherwise return an undesired result.
        directions: specify the directions over which to apply the\
            non-negativity constraint (by default, the built-in 300 direction set\
            is used). These should be supplied as a text file containing [ az el ]\
            pairs for the directions.
        lmax: the maximum spherical harmonic order for the output FOD(s).For\
            algorithms with multiple outputs, this should be provided as a\
            comma-separated list of integers, one for each output image; for\
            single-output algorithms, only a single integer should be provided. If\
            omitted, the command will use the lmax of the corresponding response\
            function (i.e based on its number of coefficients), up to a maximum of\
            8.
        mask: only perform computation within the specified binary brain mask\
            image.
        filter_: the linear frequency filtering parameters used for the initial\
            linear spherical deconvolution step (default = [ 1 1 1 0 0 ]). These\
            should be supplied as a text file containing the filtering coefficients\
            for each even harmonic order.
        neg_lambda: the regularisation parameter lambda that controls the\
            strength of the non-negativity constraint (default = 1).
        norm_lambda: the regularisation parameter lambda that controls the\
            strength of the constraint on the norm of the solution (default = 1).
        threshold: the threshold below which the amplitude of the FOD is\
            assumed to be zero, expressed as an absolute amplitude (default = 0).
        niter: the maximum number of iterations to perform for each voxel\
            (default = 50). Use '-niter 0' for a linear unconstrained spherical\
            deconvolution.
        norm_lambda_1: the regularisation parameter lambda that controls the\
            strength of the constraint on the norm of the solution (default =\
            1e-10).
        neg_lambda_1: the regularisation parameter lambda that controls the\
            strength of the non-negativity constraint (default = 1e-10).
        predicted_signal: output the predicted dwi image.
        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/dwi2fod",
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "algorithm": algorithm,
        "dwi": dwi,
        "response_odf": response_odf,
    }
    if grad is not None:
        params["grad"] = grad
    if fslgrad is not None:
        params["fslgrad"] = fslgrad
    if shells is not None:
        params["shells"] = shells
    if directions is not None:
        params["directions"] = directions
    if lmax is not None:
        params["lmax"] = lmax
    if mask is not None:
        params["mask"] = mask
    if filter_ is not None:
        params["filter"] = filter_
    if neg_lambda is not None:
        params["neg_lambda"] = neg_lambda
    if norm_lambda is not None:
        params["norm_lambda"] = norm_lambda
    if threshold is not None:
        params["threshold"] = threshold
    if niter is not None:
        params["niter"] = niter
    if norm_lambda_1 is not None:
        params["norm_lambda_1"] = norm_lambda_1
    if neg_lambda_1 is not None:
        params["neg_lambda_1"] = neg_lambda_1
    if predicted_signal is not None:
        params["predicted_signal"] = predicted_signal
    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 dwi2fod_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Dwi2fodParamsDict` 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("grad", None) is not None:
        if not isinstance(params["grad"], (pathlib.Path, str)):
            raise StyxValidationError(f'`grad` has the wrong type: Received `{type(params.get("grad", None))}` expected `InputPathType | None`')
    if params.get("fslgrad", None) is not None:
        dwi2fod_fslgrad_validate(params["fslgrad"])
    if params.get("shells", None) is not None:
        if not isinstance(params["shells"], list):
            raise StyxValidationError(f'`shells` has the wrong type: Received `{type(params.get("shells", None))}` expected `list[float] | None`')
        for e in params["shells"]:
            if not isinstance(e, (float, int)):
                raise StyxValidationError(f'`shells` has the wrong type: Received `{type(params.get("shells", None))}` expected `list[float] | None`')
    if params.get("directions", None) is not None:
        if not isinstance(params["directions"], (pathlib.Path, str)):
            raise StyxValidationError(f'`directions` has the wrong type: Received `{type(params.get("directions", None))}` expected `InputPathType | None`')
    if params.get("lmax", None) is not None:
        if not isinstance(params["lmax"], list):
            raise StyxValidationError(f'`lmax` has the wrong type: Received `{type(params.get("lmax", None))}` expected `list[int] | None`')
        for e in params["lmax"]:
            if not isinstance(e, int):
                raise StyxValidationError(f'`lmax` has the wrong type: Received `{type(params.get("lmax", None))}` expected `list[int] | None`')
    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("filter", None) is not None:
        if not isinstance(params["filter"], (pathlib.Path, str)):
            raise StyxValidationError(f'`filter` has the wrong type: Received `{type(params.get("filter", None))}` expected `InputPathType | None`')
    if params.get("neg_lambda", None) is not None:
        if not isinstance(params["neg_lambda"], (float, int)):
            raise StyxValidationError(f'`neg_lambda` has the wrong type: Received `{type(params.get("neg_lambda", None))}` expected `float | None`')
    if params.get("norm_lambda", None) is not None:
        if not isinstance(params["norm_lambda"], (float, int)):
            raise StyxValidationError(f'`norm_lambda` has the wrong type: Received `{type(params.get("norm_lambda", 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("niter", None) is not None:
        if not isinstance(params["niter"], int):
            raise StyxValidationError(f'`niter` has the wrong type: Received `{type(params.get("niter", None))}` expected `int | None`')
    if params.get("norm_lambda_1", None) is not None:
        if not isinstance(params["norm_lambda_1"], (float, int)):
            raise StyxValidationError(f'`norm_lambda_1` has the wrong type: Received `{type(params.get("norm_lambda_1", None))}` expected `float | None`')
    if params.get("neg_lambda_1", None) is not None:
        if not isinstance(params["neg_lambda_1"], (float, int)):
            raise StyxValidationError(f'`neg_lambda_1` has the wrong type: Received `{type(params.get("neg_lambda_1", None))}` expected `float | None`')
    if params.get("predicted_signal", None) is not None:
        if not isinstance(params["predicted_signal"], str):
            raise StyxValidationError(f'`predicted_signal` has the wrong type: Received `{type(params.get("predicted_signal", 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\"]")
        dwi2fod_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[Dwi2fodConfigParamsDict] | None`')
        for e in params["config"]:
            dwi2fod_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("algorithm", None) is None:
        raise StyxValidationError("`algorithm` must not be None")
    if not isinstance(params["algorithm"], str):
        raise StyxValidationError(f'`algorithm` has the wrong type: Received `{type(params.get("algorithm", None))}` expected `str`')
    if params.get("dwi", None) is None:
        raise StyxValidationError("`dwi` must not be None")
    if not isinstance(params["dwi"], (pathlib.Path, str)):
        raise StyxValidationError(f'`dwi` has the wrong type: Received `{type(params.get("dwi", None))}` expected `InputPathType`')
    if params.get("response_odf", None) is None:
        raise StyxValidationError("`response_odf` must not be None")
    if not isinstance(params["response_odf"], list):
        raise StyxValidationError(f'`response_odf` has the wrong type: Received `{type(params.get("response_odf", None))}` expected `list[Dwi2fodResponseOdfParamsDict]`')
    for e in params["response_odf"]:
        dwi2fod_response_odf_validate(e)


def dwi2fod_cargs(
    params: Dwi2fodParamsDict,
    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("dwi2fod")
    if params.get("grad", None) is not None:
        cargs.extend([
            "-grad",
            execution.input_file(params.get("grad", None))
        ])
    if params.get("fslgrad", None) is not None:
        cargs.extend(dwi2fod_fslgrad_cargs(params.get("fslgrad", None), execution))
    if params.get("shells", None) is not None:
        cargs.extend([
            "-shells",
            ",".join(map(str, params.get("shells", None)))
        ])
    if params.get("directions", None) is not None:
        cargs.extend([
            "-directions",
            execution.input_file(params.get("directions", None))
        ])
    if params.get("lmax", None) is not None:
        cargs.extend([
            "-lmax",
            ",".join(map(str, params.get("lmax", None)))
        ])
    if params.get("mask", None) is not None:
        cargs.extend([
            "-mask",
            execution.input_file(params.get("mask", None))
        ])
    if params.get("filter", None) is not None:
        cargs.extend([
            "-filter",
            execution.input_file(params.get("filter", None))
        ])
    if params.get("neg_lambda", None) is not None:
        cargs.extend([
            "-neg_lambda",
            str(params.get("neg_lambda", None))
        ])
    if params.get("norm_lambda", None) is not None:
        cargs.extend([
            "-norm_lambda",
            str(params.get("norm_lambda", None))
        ])
    if params.get("threshold", None) is not None:
        cargs.extend([
            "-threshold",
            str(params.get("threshold", None))
        ])
    if params.get("niter", None) is not None:
        cargs.extend([
            "-niter",
            str(params.get("niter", None))
        ])
    if params.get("norm_lambda_1", None) is not None:
        cargs.extend([
            "-norm_lambda",
            str(params.get("norm_lambda_1", None))
        ])
    if params.get("neg_lambda_1", None) is not None:
        cargs.extend([
            "-neg_lambda",
            str(params.get("neg_lambda_1", None))
        ])
    if params.get("predicted_signal", None) is not None:
        cargs.extend([
            "-predicted_signal",
            params.get("predicted_signal", None)
        ])
    if params.get("strides", None) is not None:
        cargs.extend([
            "-strides",
            *dwi2fod_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 [dwi2fod_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(params.get("algorithm", None))
    cargs.append(execution.input_file(params.get("dwi", None)))
    cargs.extend([a for c in [dwi2fod_response_odf_cargs(s, execution) for s in params.get("response_odf", None)] for a in c])
    return cargs


def dwi2fod_outputs(
    params: Dwi2fodParamsDict,
    execution: Execution,
) -> Dwi2fodOutputs:
    """
    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 = Dwi2fodOutputs(
        root=execution.output_file("."),
        predicted_signal=execution.output_file(params.get("predicted_signal", None)) if (params.get("predicted_signal") is not None) else None,
        response_odf=[dwi2fod_response_odf_outputs(i, execution) if dwi2fod_response_odf_outputs else None for i in params.get("response_odf")],
    )
    return ret


def dwi2fod_execute(
    params: Dwi2fodParamsDict,
    runner: Runner | None = None,
) -> Dwi2fodOutputs:
    """
    dwi2fod
    
    Estimate fibre orientation distributions from diffusion data using spherical
    deconvolution.
    
    The spherical harmonic coefficients are stored according the conventions
    described the main documentation, which can be found at the following link:
    https://mrtrix.readthedocs.io/en/3.0.4/concepts/spherical_harmonics.html
    
    References:
    
    * If using csd algorithm:
    Tournier, J.-D.; Calamante, F. & Connelly, A. Robust determination of the
    fibre orientation distribution in diffusion MRI: Non-negativity constrained
    super-resolved spherical deconvolution. NeuroImage, 2007, 35, 1459-1472
    
    * If using msmt_csd algorithm:
    Jeurissen, B; Tournier, J-D; Dhollander, T; Connelly, A & Sijbers, J.
    Multi-tissue constrained spherical deconvolution for improved analysis of
    multi-shell diffusion MRI data. NeuroImage, 2014, 103, 411-426
    
    Tournier, J.-D.; Calamante, F., Gadian, D.G. & Connelly, A. Direct
    estimation of the fiber orientation density function from diffusion-weighted
    MRI data using spherical deconvolution. NeuroImage, 2004, 23, 1176-1185.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Dwi2fodOutputs`).
    """
    dwi2fod_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(DWI2FOD_METADATA)
    params = execution.params(params)
    cargs = dwi2fod_cargs(params, execution)
    ret = dwi2fod_outputs(params, execution)
    execution.run(cargs)
    return ret


def dwi2fod(
    algorithm: str,
    dwi: InputPathType,
    response_odf: list[Dwi2fodResponseOdfParamsDict],
    grad: InputPathType | None = None,
    fslgrad: Dwi2fodFslgradParamsDict | None = None,
    shells: list[float] | None = None,
    directions: InputPathType | None = None,
    lmax: list[int] | None = None,
    mask: InputPathType | None = None,
    filter_: InputPathType | None = None,
    neg_lambda: float | None = None,
    norm_lambda: float | None = None,
    threshold: float | None = None,
    niter: int | None = None,
    norm_lambda_1: float | None = None,
    neg_lambda_1: float | None = None,
    predicted_signal: str | None = None,
    strides: typing.Union[Dwi2fodVariousStringParamsDictTagged, Dwi2fodVariousFileParamsDictTagged] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Dwi2fodConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> Dwi2fodOutputs:
    """
    dwi2fod
    
    Estimate fibre orientation distributions from diffusion data using spherical
    deconvolution.
    
    The spherical harmonic coefficients are stored according the conventions
    described the main documentation, which can be found at the following link:
    https://mrtrix.readthedocs.io/en/3.0.4/concepts/spherical_harmonics.html
    
    References:
    
    * If using csd algorithm:
    Tournier, J.-D.; Calamante, F. & Connelly, A. Robust determination of the
    fibre orientation distribution in diffusion MRI: Non-negativity constrained
    super-resolved spherical deconvolution. NeuroImage, 2007, 35, 1459-1472
    
    * If using msmt_csd algorithm:
    Jeurissen, B; Tournier, J-D; Dhollander, T; Connelly, A & Sijbers, J.
    Multi-tissue constrained spherical deconvolution for improved analysis of
    multi-shell diffusion MRI data. NeuroImage, 2014, 103, 411-426
    
    Tournier, J.-D.; Calamante, F., Gadian, D.G. & Connelly, A. Direct
    estimation of the fiber orientation density function from diffusion-weighted
    MRI data using spherical deconvolution. NeuroImage, 2004, 23, 1176-1185.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        algorithm: the algorithm to use for FOD estimation. (options are:\
            csd,msmt_csd).
        dwi: the input diffusion-weighted image.
        response_odf: pairs of input tissue response and output ODF images.
        grad: Provide the diffusion-weighted gradient scheme used in the\
            acquisition in a text file. This should be supplied as a 4xN text file\
            with each line is in the format [ X Y Z b ], where [ X Y Z ] describe\
            the direction of the applied gradient, and b gives the b-value in units\
            of s/mm^2. If a diffusion gradient scheme is present in the input image\
            header, the data provided with this option will be instead used.
        fslgrad: Provide the diffusion-weighted gradient scheme used in the\
            acquisition in FSL bvecs/bvals format files. If a diffusion gradient\
            scheme is present in the input image header, the data provided with\
            this option will be instead used.
        shells: specify one or more b-values to use during processing, as a\
            comma-separated list of the desired approximate b-values (b-values are\
            clustered to allow for small deviations). Note that some commands are\
            incompatible with multiple b-values, and will report an error if more\
            than one b-value is provided.\
            WARNING: note that, even though the b=0 volumes are never referred\
            to as shells in the literature, they still have to be explicitly\
            included in the list of b-values as provided to the -shell option!\
            Several algorithms which include the b=0 volumes in their\
            computations may otherwise return an undesired result.
        directions: specify the directions over which to apply the\
            non-negativity constraint (by default, the built-in 300 direction set\
            is used). These should be supplied as a text file containing [ az el ]\
            pairs for the directions.
        lmax: the maximum spherical harmonic order for the output FOD(s).For\
            algorithms with multiple outputs, this should be provided as a\
            comma-separated list of integers, one for each output image; for\
            single-output algorithms, only a single integer should be provided. If\
            omitted, the command will use the lmax of the corresponding response\
            function (i.e based on its number of coefficients), up to a maximum of\
            8.
        mask: only perform computation within the specified binary brain mask\
            image.
        filter_: the linear frequency filtering parameters used for the initial\
            linear spherical deconvolution step (default = [ 1 1 1 0 0 ]). These\
            should be supplied as a text file containing the filtering coefficients\
            for each even harmonic order.
        neg_lambda: the regularisation parameter lambda that controls the\
            strength of the non-negativity constraint (default = 1).
        norm_lambda: the regularisation parameter lambda that controls the\
            strength of the constraint on the norm of the solution (default = 1).
        threshold: the threshold below which the amplitude of the FOD is\
            assumed to be zero, expressed as an absolute amplitude (default = 0).
        niter: the maximum number of iterations to perform for each voxel\
            (default = 50). Use '-niter 0' for a linear unconstrained spherical\
            deconvolution.
        norm_lambda_1: the regularisation parameter lambda that controls the\
            strength of the constraint on the norm of the solution (default =\
            1e-10).
        neg_lambda_1: the regularisation parameter lambda that controls the\
            strength of the non-negativity constraint (default = 1e-10).
        predicted_signal: output the predicted dwi image.
        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 `Dwi2fodOutputs`).
    """
    params = dwi2fod_params(
        grad=grad,
        fslgrad=fslgrad,
        shells=shells,
        directions=directions,
        lmax=lmax,
        mask=mask,
        filter_=filter_,
        neg_lambda=neg_lambda,
        norm_lambda=norm_lambda,
        threshold=threshold,
        niter=niter,
        norm_lambda_1=norm_lambda_1,
        neg_lambda_1=neg_lambda_1,
        predicted_signal=predicted_signal,
        strides=strides,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        algorithm=algorithm,
        dwi=dwi,
        response_odf=response_odf,
    )
    return dwi2fod_execute(params, runner)


__all__ = [
    "DWI2FOD_METADATA",
    "Dwi2fodConfigParamsDict",
    "Dwi2fodConfigParamsDictTagged",
    "Dwi2fodFslgradParamsDict",
    "Dwi2fodFslgradParamsDictTagged",
    "Dwi2fodOutputs",
    "Dwi2fodParamsDict",
    "Dwi2fodParamsDictTagged",
    "Dwi2fodResponseOdfOutputs",
    "Dwi2fodResponseOdfParamsDict",
    "Dwi2fodResponseOdfParamsDictTagged",
    "Dwi2fodVariousFileParamsDict",
    "Dwi2fodVariousFileParamsDictTagged",
    "Dwi2fodVariousStringParamsDict",
    "Dwi2fodVariousStringParamsDictTagged",
    "dwi2fod",
    "dwi2fod_config",
    "dwi2fod_execute",
    "dwi2fod_fslgrad",
    "dwi2fod_params",
    "dwi2fod_response_odf",
    "dwi2fod_various_file",
    "dwi2fod_various_string",
]
