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

import typing
import pathlib
from styxdefs import *

DWIEXTRACT_METADATA = Metadata(
    id="0021ca6ba5d653dd2d95adc256257bec0ea68206.boutiques",
    name="dwiextract",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_DwiextractFslgradParamsDictNoTag = typing.TypedDict('_DwiextractFslgradParamsDictNoTag', {
    "bvecs": InputPathType,
    "bvals": InputPathType,
})
DwiextractFslgradParamsDictTagged = typing.TypedDict('DwiextractFslgradParamsDictTagged', {
    "@type": typing.Literal["fslgrad"],
    "bvecs": InputPathType,
    "bvals": InputPathType,
})
DwiextractFslgradParamsDict = _DwiextractFslgradParamsDictNoTag | DwiextractFslgradParamsDictTagged


_DwiextractExportGradFslParamsDictNoTag = typing.TypedDict('_DwiextractExportGradFslParamsDictNoTag', {
    "bvecs_path": str,
    "bvals_path": str,
})
DwiextractExportGradFslParamsDictTagged = typing.TypedDict('DwiextractExportGradFslParamsDictTagged', {
    "@type": typing.Literal["export_grad_fsl"],
    "bvecs_path": str,
    "bvals_path": str,
})
DwiextractExportGradFslParamsDict = _DwiextractExportGradFslParamsDictNoTag | DwiextractExportGradFslParamsDictTagged


_DwiextractImportPeEddyParamsDictNoTag = typing.TypedDict('_DwiextractImportPeEddyParamsDictNoTag', {
    "config": InputPathType,
    "indices": InputPathType,
})
DwiextractImportPeEddyParamsDictTagged = typing.TypedDict('DwiextractImportPeEddyParamsDictTagged', {
    "@type": typing.Literal["import_pe_eddy"],
    "config": InputPathType,
    "indices": InputPathType,
})
DwiextractImportPeEddyParamsDict = _DwiextractImportPeEddyParamsDictNoTag | DwiextractImportPeEddyParamsDictTagged


_DwiextractVariousStringParamsDictNoTag = typing.TypedDict('_DwiextractVariousStringParamsDictNoTag', {
    "obj": str,
})
DwiextractVariousStringParamsDictTagged = typing.TypedDict('DwiextractVariousStringParamsDictTagged', {
    "@type": typing.Literal["VariousString"],
    "obj": str,
})
DwiextractVariousStringParamsDict = _DwiextractVariousStringParamsDictNoTag | DwiextractVariousStringParamsDictTagged


_DwiextractVariousFileParamsDictNoTag = typing.TypedDict('_DwiextractVariousFileParamsDictNoTag', {
    "obj": InputPathType,
})
DwiextractVariousFileParamsDictTagged = typing.TypedDict('DwiextractVariousFileParamsDictTagged', {
    "@type": typing.Literal["VariousFile"],
    "obj": InputPathType,
})
DwiextractVariousFileParamsDict = _DwiextractVariousFileParamsDictNoTag | DwiextractVariousFileParamsDictTagged


_DwiextractConfigParamsDictNoTag = typing.TypedDict('_DwiextractConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
DwiextractConfigParamsDictTagged = typing.TypedDict('DwiextractConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
DwiextractConfigParamsDict = _DwiextractConfigParamsDictNoTag | DwiextractConfigParamsDictTagged


_DwiextractParamsDictNoTag = typing.TypedDict('_DwiextractParamsDictNoTag', {
    "bzero": bool,
    "no_bzero": bool,
    "singleshell": bool,
    "grad": typing.NotRequired[InputPathType | None],
    "fslgrad": typing.NotRequired[DwiextractFslgradParamsDict | None],
    "shells": typing.NotRequired[list[float] | None],
    "export_grad_mrtrix": typing.NotRequired[str | None],
    "export_grad_fsl": typing.NotRequired[DwiextractExportGradFslParamsDict | None],
    "import_pe_table": typing.NotRequired[InputPathType | None],
    "import_pe_eddy": typing.NotRequired[DwiextractImportPeEddyParamsDict | None],
    "pe": typing.NotRequired[list[float] | None],
    "strides": typing.NotRequired[typing.Union[DwiextractVariousStringParamsDictTagged, DwiextractVariousFileParamsDictTagged] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[DwiextractConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "output": str,
})
DwiextractParamsDictTagged = typing.TypedDict('DwiextractParamsDictTagged', {
    "@type": typing.Literal["mrtrix/dwiextract"],
    "bzero": bool,
    "no_bzero": bool,
    "singleshell": bool,
    "grad": typing.NotRequired[InputPathType | None],
    "fslgrad": typing.NotRequired[DwiextractFslgradParamsDict | None],
    "shells": typing.NotRequired[list[float] | None],
    "export_grad_mrtrix": typing.NotRequired[str | None],
    "export_grad_fsl": typing.NotRequired[DwiextractExportGradFslParamsDict | None],
    "import_pe_table": typing.NotRequired[InputPathType | None],
    "import_pe_eddy": typing.NotRequired[DwiextractImportPeEddyParamsDict | None],
    "pe": typing.NotRequired[list[float] | None],
    "strides": typing.NotRequired[typing.Union[DwiextractVariousStringParamsDictTagged, DwiextractVariousFileParamsDictTagged] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[DwiextractConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "output": str,
})
DwiextractParamsDict = _DwiextractParamsDictNoTag | DwiextractParamsDictTagged


def dwiextract_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": dwiextract_various_string_cargs,
        "VariousFile": dwiextract_various_file_cargs,
    }.get(t)


def dwiextract_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": dwiextract_various_string_validate,
        "VariousFile": dwiextract_various_file_validate,
    }.get(t)


def dwiextract_fslgrad(
    bvecs: InputPathType,
    bvals: InputPathType,
) -> DwiextractFslgradParamsDictTagged:
    """
    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 dwiextract_fslgrad_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `DwiextractFslgradParamsDict` 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 dwiextract_fslgrad_cargs(
    params: DwiextractFslgradParamsDict,
    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


class DwiextractExportGradFslOutputs(typing.NamedTuple):
    """
    Output object returned when calling `DwiextractExportGradFslParamsDict | None(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    bvecs_path: OutputPathType
    """export the diffusion-weighted gradient table to files in FSL (bvecs /
    bvals) format"""
    bvals_path: OutputPathType
    """export the diffusion-weighted gradient table to files in FSL (bvecs /
    bvals) format"""


def dwiextract_export_grad_fsl(
    bvecs_path: str,
    bvals_path: str,
) -> DwiextractExportGradFslParamsDictTagged:
    """
    Build parameters.
    
    Args:
        bvecs_path: export the diffusion-weighted gradient table to files in\
            FSL (bvecs / bvals) format.
        bvals_path: export the diffusion-weighted gradient table to files in\
            FSL (bvecs / bvals) format.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "export_grad_fsl",
        "bvecs_path": bvecs_path,
        "bvals_path": bvals_path,
    }
    return params


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


def dwiextract_export_grad_fsl_cargs(
    params: DwiextractExportGradFslParamsDict,
    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("-export_grad_fsl")
    cargs.append(params.get("bvecs_path", None))
    cargs.append(params.get("bvals_path", None))
    return cargs


def dwiextract_export_grad_fsl_outputs(
    params: DwiextractExportGradFslParamsDict,
    execution: Execution,
) -> DwiextractExportGradFslOutputs:
    """
    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 = DwiextractExportGradFslOutputs(
        root=execution.output_file("."),
        bvecs_path=execution.output_file(params.get("bvecs_path", None)),
        bvals_path=execution.output_file(params.get("bvals_path", None)),
    )
    return ret


def dwiextract_import_pe_eddy(
    config: InputPathType,
    indices: InputPathType,
) -> DwiextractImportPeEddyParamsDictTagged:
    """
    Build parameters.
    
    Args:
        config: import phase-encoding information from an EDDY-style config /\
            index file pair.
        indices: import phase-encoding information from an EDDY-style config /\
            index file pair.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "import_pe_eddy",
        "config": config,
        "indices": indices,
    }
    return params


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


def dwiextract_import_pe_eddy_cargs(
    params: DwiextractImportPeEddyParamsDict,
    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("-import_pe_eddy")
    cargs.append(execution.input_file(params.get("config", None)))
    cargs.append(execution.input_file(params.get("indices", None)))
    return cargs


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


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


def dwiextract_various_file_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `DwiextractVariousFileParamsDict` 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 dwiextract_various_file_cargs(
    params: DwiextractVariousFileParamsDict,
    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 dwiextract_config(
    key: str,
    value: str,
) -> DwiextractConfigParamsDictTagged:
    """
    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 dwiextract_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `DwiextractConfigParamsDict` 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 dwiextract_config_cargs(
    params: DwiextractConfigParamsDict,
    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 DwiextractOutputs(typing.NamedTuple):
    """
    Output object returned when calling `DwiextractParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """the output image (diffusion-weighted volumes by default)."""
    export_grad_mrtrix: OutputPathType | None
    """export the diffusion-weighted gradient table to file in MRtrix format """
    export_grad_fsl: DwiextractExportGradFslOutputs | None
    """Outputs from `dwiextract_export_grad_fsl_outputs`."""


def dwiextract_params(
    input_: InputPathType,
    output: str,
    bzero: bool = False,
    no_bzero: bool = False,
    singleshell: bool = False,
    grad: InputPathType | None = None,
    fslgrad: DwiextractFslgradParamsDict | None = None,
    shells: list[float] | None = None,
    export_grad_mrtrix: str | None = None,
    export_grad_fsl: DwiextractExportGradFslParamsDict | None = None,
    import_pe_table: InputPathType | None = None,
    import_pe_eddy: DwiextractImportPeEddyParamsDict | None = None,
    pe: list[float] | None = None,
    strides: typing.Union[DwiextractVariousStringParamsDictTagged, DwiextractVariousFileParamsDictTagged] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[DwiextractConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> DwiextractParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: the input DW image.
        output: the output image (diffusion-weighted volumes by default).
        bzero: Output b=0 volumes (instead of the diffusion weighted volumes,\
            if -singleshell is not specified).
        no_bzero: Output only non b=0 volumes (default, if -singleshell is not\
            specified).
        singleshell: Force a single-shell (single non b=0 shell) output. This\
            will include b=0 volumes, if present. Use with -bzero to enforce\
            presence of b=0 volumes (error if not present) or with -no_bzero to\
            exclude them.
        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.
        export_grad_mrtrix: export the diffusion-weighted gradient table to\
            file in MRtrix format.
        export_grad_fsl: export the diffusion-weighted gradient table to files\
            in FSL (bvecs / bvals) format.
        import_pe_table: import a phase-encoding table from file.
        import_pe_eddy: import phase-encoding information from an EDDY-style\
            config / index file pair.
        pe: select volumes with a particular phase encoding; this can be three\
            comma-separated values (for i,j,k components of vector direction) or\
            four (direction & total readout time).
        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/dwiextract",
        "bzero": bzero,
        "no_bzero": no_bzero,
        "singleshell": singleshell,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "input": input_,
        "output": output,
    }
    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 export_grad_mrtrix is not None:
        params["export_grad_mrtrix"] = export_grad_mrtrix
    if export_grad_fsl is not None:
        params["export_grad_fsl"] = export_grad_fsl
    if import_pe_table is not None:
        params["import_pe_table"] = import_pe_table
    if import_pe_eddy is not None:
        params["import_pe_eddy"] = import_pe_eddy
    if pe is not None:
        params["pe"] = pe
    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 dwiextract_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `DwiextractParamsDict` 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("bzero", False) is None:
        raise StyxValidationError("`bzero` must not be None")
    if not isinstance(params["bzero"], bool):
        raise StyxValidationError(f'`bzero` has the wrong type: Received `{type(params.get("bzero", False))}` expected `bool`')
    if params.get("no_bzero", False) is None:
        raise StyxValidationError("`no_bzero` must not be None")
    if not isinstance(params["no_bzero"], bool):
        raise StyxValidationError(f'`no_bzero` has the wrong type: Received `{type(params.get("no_bzero", False))}` expected `bool`')
    if params.get("singleshell", False) is None:
        raise StyxValidationError("`singleshell` must not be None")
    if not isinstance(params["singleshell"], bool):
        raise StyxValidationError(f'`singleshell` has the wrong type: Received `{type(params.get("singleshell", False))}` expected `bool`')
    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:
        dwiextract_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("export_grad_mrtrix", None) is not None:
        if not isinstance(params["export_grad_mrtrix"], str):
            raise StyxValidationError(f'`export_grad_mrtrix` has the wrong type: Received `{type(params.get("export_grad_mrtrix", None))}` expected `str | None`')
    if params.get("export_grad_fsl", None) is not None:
        dwiextract_export_grad_fsl_validate(params["export_grad_fsl"])
    if params.get("import_pe_table", None) is not None:
        if not isinstance(params["import_pe_table"], (pathlib.Path, str)):
            raise StyxValidationError(f'`import_pe_table` has the wrong type: Received `{type(params.get("import_pe_table", None))}` expected `InputPathType | None`')
    if params.get("import_pe_eddy", None) is not None:
        dwiextract_import_pe_eddy_validate(params["import_pe_eddy"])
    if params.get("pe", None) is not None:
        if not isinstance(params["pe"], list):
            raise StyxValidationError(f'`pe` has the wrong type: Received `{type(params.get("pe", None))}` expected `list[float] | None`')
        for e in params["pe"]:
            if not isinstance(e, (float, int)):
                raise StyxValidationError(f'`pe` has the wrong type: Received `{type(params.get("pe", None))}` expected `list[float] | 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\"]")
        dwiextract_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[DwiextractConfigParamsDict] | None`')
        for e in params["config"]:
            dwiextract_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 dwiextract_cargs(
    params: DwiextractParamsDict,
    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("dwiextract")
    if params.get("bzero", False):
        cargs.append("-bzero")
    if params.get("no_bzero", False):
        cargs.append("-no_bzero")
    if params.get("singleshell", False):
        cargs.append("-singleshell")
    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(dwiextract_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("export_grad_mrtrix", None) is not None:
        cargs.extend([
            "-export_grad_mrtrix",
            params.get("export_grad_mrtrix", None)
        ])
    if params.get("export_grad_fsl", None) is not None:
        cargs.extend(dwiextract_export_grad_fsl_cargs(params.get("export_grad_fsl", None), execution))
    if params.get("import_pe_table", None) is not None:
        cargs.extend([
            "-import_pe_table",
            execution.input_file(params.get("import_pe_table", None))
        ])
    if params.get("import_pe_eddy", None) is not None:
        cargs.extend(dwiextract_import_pe_eddy_cargs(params.get("import_pe_eddy", None), execution))
    if params.get("pe", None) is not None:
        cargs.extend([
            "-pe",
            ",".join(map(str, params.get("pe", None)))
        ])
    if params.get("strides", None) is not None:
        cargs.extend([
            "-strides",
            *dwiextract_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 [dwiextract_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 dwiextract_outputs(
    params: DwiextractParamsDict,
    execution: Execution,
) -> DwiextractOutputs:
    """
    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 = DwiextractOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
        export_grad_mrtrix=execution.output_file(params.get("export_grad_mrtrix", None)) if (params.get("export_grad_mrtrix") is not None) else None,
        export_grad_fsl=dwiextract_export_grad_fsl_outputs(params.get("export_grad_fsl"), execution) if params.get("export_grad_fsl") else None,
    )
    return ret


def dwiextract_execute(
    params: DwiextractParamsDict,
    runner: Runner | None = None,
) -> DwiextractOutputs:
    """
    dwiextract
    
    Extract diffusion-weighted volumes, b=0 volumes, or certain shells from a
    DWI dataset.
    
    
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `DwiextractOutputs`).
    """
    dwiextract_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(DWIEXTRACT_METADATA)
    params = execution.params(params)
    cargs = dwiextract_cargs(params, execution)
    ret = dwiextract_outputs(params, execution)
    execution.run(cargs)
    return ret


def dwiextract(
    input_: InputPathType,
    output: str,
    bzero: bool = False,
    no_bzero: bool = False,
    singleshell: bool = False,
    grad: InputPathType | None = None,
    fslgrad: DwiextractFslgradParamsDict | None = None,
    shells: list[float] | None = None,
    export_grad_mrtrix: str | None = None,
    export_grad_fsl: DwiextractExportGradFslParamsDict | None = None,
    import_pe_table: InputPathType | None = None,
    import_pe_eddy: DwiextractImportPeEddyParamsDict | None = None,
    pe: list[float] | None = None,
    strides: typing.Union[DwiextractVariousStringParamsDictTagged, DwiextractVariousFileParamsDictTagged] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[DwiextractConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> DwiextractOutputs:
    """
    dwiextract
    
    Extract diffusion-weighted volumes, b=0 volumes, or certain shells from a
    DWI dataset.
    
    
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        input_: the input DW image.
        output: the output image (diffusion-weighted volumes by default).
        bzero: Output b=0 volumes (instead of the diffusion weighted volumes,\
            if -singleshell is not specified).
        no_bzero: Output only non b=0 volumes (default, if -singleshell is not\
            specified).
        singleshell: Force a single-shell (single non b=0 shell) output. This\
            will include b=0 volumes, if present. Use with -bzero to enforce\
            presence of b=0 volumes (error if not present) or with -no_bzero to\
            exclude them.
        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.
        export_grad_mrtrix: export the diffusion-weighted gradient table to\
            file in MRtrix format.
        export_grad_fsl: export the diffusion-weighted gradient table to files\
            in FSL (bvecs / bvals) format.
        import_pe_table: import a phase-encoding table from file.
        import_pe_eddy: import phase-encoding information from an EDDY-style\
            config / index file pair.
        pe: select volumes with a particular phase encoding; this can be three\
            comma-separated values (for i,j,k components of vector direction) or\
            four (direction & total readout time).
        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 `DwiextractOutputs`).
    """
    params = dwiextract_params(
        bzero=bzero,
        no_bzero=no_bzero,
        singleshell=singleshell,
        grad=grad,
        fslgrad=fslgrad,
        shells=shells,
        export_grad_mrtrix=export_grad_mrtrix,
        export_grad_fsl=export_grad_fsl,
        import_pe_table=import_pe_table,
        import_pe_eddy=import_pe_eddy,
        pe=pe,
        strides=strides,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        input_=input_,
        output=output,
    )
    return dwiextract_execute(params, runner)


__all__ = [
    "DWIEXTRACT_METADATA",
    "DwiextractConfigParamsDict",
    "DwiextractConfigParamsDictTagged",
    "DwiextractExportGradFslOutputs",
    "DwiextractExportGradFslParamsDict",
    "DwiextractExportGradFslParamsDictTagged",
    "DwiextractFslgradParamsDict",
    "DwiextractFslgradParamsDictTagged",
    "DwiextractImportPeEddyParamsDict",
    "DwiextractImportPeEddyParamsDictTagged",
    "DwiextractOutputs",
    "DwiextractParamsDict",
    "DwiextractParamsDictTagged",
    "DwiextractVariousFileParamsDict",
    "DwiextractVariousFileParamsDictTagged",
    "DwiextractVariousStringParamsDict",
    "DwiextractVariousStringParamsDictTagged",
    "dwiextract",
    "dwiextract_config",
    "dwiextract_execute",
    "dwiextract_export_grad_fsl",
    "dwiextract_fslgrad",
    "dwiextract_import_pe_eddy",
    "dwiextract_params",
    "dwiextract_various_file",
    "dwiextract_various_string",
]
