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

import typing
import pathlib
from styxdefs import *

WARP2METRIC_METADATA = Metadata(
    id="6239916d39fe990e43c4b408dab7798207712e0c.boutiques",
    name="warp2metric",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_Warp2metricFcParamsDictNoTag = typing.TypedDict('_Warp2metricFcParamsDictNoTag', {
    "template_fixel_directory": InputPathType,
    "output_fixel_directory": str,
    "output_fixel_data": str,
})
Warp2metricFcParamsDictTagged = typing.TypedDict('Warp2metricFcParamsDictTagged', {
    "@type": typing.Literal["fc"],
    "template_fixel_directory": InputPathType,
    "output_fixel_directory": str,
    "output_fixel_data": str,
})
Warp2metricFcParamsDict = _Warp2metricFcParamsDictNoTag | Warp2metricFcParamsDictTagged


_Warp2metricConfigParamsDictNoTag = typing.TypedDict('_Warp2metricConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
Warp2metricConfigParamsDictTagged = typing.TypedDict('Warp2metricConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
Warp2metricConfigParamsDict = _Warp2metricConfigParamsDictNoTag | Warp2metricConfigParamsDictTagged


_Warp2metricParamsDictNoTag = typing.TypedDict('_Warp2metricParamsDictNoTag', {
    "fc": typing.NotRequired[Warp2metricFcParamsDict | None],
    "jmat": typing.NotRequired[str | None],
    "jdet": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Warp2metricConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "in": InputPathType,
})
Warp2metricParamsDictTagged = typing.TypedDict('Warp2metricParamsDictTagged', {
    "@type": typing.Literal["mrtrix/warp2metric"],
    "fc": typing.NotRequired[Warp2metricFcParamsDict | None],
    "jmat": typing.NotRequired[str | None],
    "jdet": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Warp2metricConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "in": InputPathType,
})
Warp2metricParamsDict = _Warp2metricParamsDictNoTag | Warp2metricParamsDictTagged


def warp2metric_fc(
    template_fixel_directory: InputPathType,
    output_fixel_directory: str,
    output_fixel_data: str,
) -> Warp2metricFcParamsDictTagged:
    """
    Build parameters.
    
    Args:
        template_fixel_directory: use an input template fixel image to define\
            fibre orientations and output a fixel image describing the change in\
            fibre cross-section (FC) in the perpendicular plane to the fixel\
            orientation. e.g. warp2metric warp.mif -fc fixel_template_directory\
            output_fixel_directory fc.mif.
        output_fixel_directory: use an input template fixel image to define\
            fibre orientations and output a fixel image describing the change in\
            fibre cross-section (FC) in the perpendicular plane to the fixel\
            orientation. e.g. warp2metric warp.mif -fc fixel_template_directory\
            output_fixel_directory fc.mif.
        output_fixel_data: use an input template fixel image to define fibre\
            orientations and output a fixel image describing the change in fibre\
            cross-section (FC) in the perpendicular plane to the fixel orientation.\
            e.g. warp2metric warp.mif -fc fixel_template_directory\
            output_fixel_directory fc.mif.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "fc",
        "template_fixel_directory": template_fixel_directory,
        "output_fixel_directory": output_fixel_directory,
        "output_fixel_data": output_fixel_data,
    }
    return params


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


def warp2metric_fc_cargs(
    params: Warp2metricFcParamsDict,
    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("-fc")
    cargs.append(execution.input_file(params.get("template_fixel_directory", None)))
    cargs.append(params.get("output_fixel_directory", None))
    cargs.append(params.get("output_fixel_data", None))
    return cargs


def warp2metric_config(
    key: str,
    value: str,
) -> Warp2metricConfigParamsDictTagged:
    """
    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 warp2metric_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Warp2metricConfigParamsDict` 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 warp2metric_config_cargs(
    params: Warp2metricConfigParamsDict,
    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 Warp2metricOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Warp2metricParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    jmat: OutputPathType | None
    """output a Jacobian matrix image stored in column-major order along the 4th
    dimension.Note the output jacobian describes the warp gradient w.r.t the
    scanner space coordinate system """
    jdet: OutputPathType | None
    """output the Jacobian determinant instead of the full matrix """


def warp2metric_params(
    in_: InputPathType,
    fc: Warp2metricFcParamsDict | None = None,
    jmat: str | None = None,
    jdet: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Warp2metricConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> Warp2metricParamsDictTagged:
    """
    Build parameters.
    
    Args:
        in_: the input deformation field.
        fc: use an input template fixel image to define fibre orientations and\
            output a fixel image describing the change in fibre cross-section (FC)\
            in the perpendicular plane to the fixel orientation. e.g. warp2metric\
            warp.mif -fc fixel_template_directory output_fixel_directory fc.mif.
        jmat: output a Jacobian matrix image stored in column-major order along\
            the 4th dimension.Note the output jacobian describes the warp gradient\
            w.r.t the scanner space coordinate system.
        jdet: output the Jacobian determinant instead of the full matrix.
        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/warp2metric",
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "in": in_,
    }
    if fc is not None:
        params["fc"] = fc
    if jmat is not None:
        params["jmat"] = jmat
    if jdet is not None:
        params["jdet"] = jdet
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def warp2metric_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Warp2metricParamsDict` 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("fc", None) is not None:
        warp2metric_fc_validate(params["fc"])
    if params.get("jmat", None) is not None:
        if not isinstance(params["jmat"], str):
            raise StyxValidationError(f'`jmat` has the wrong type: Received `{type(params.get("jmat", None))}` expected `str | None`')
    if params.get("jdet", None) is not None:
        if not isinstance(params["jdet"], str):
            raise StyxValidationError(f'`jdet` has the wrong type: Received `{type(params.get("jdet", None))}` expected `str | None`')
    if params.get("info", False) is None:
        raise StyxValidationError("`info` must not be None")
    if not isinstance(params["info"], bool):
        raise StyxValidationError(f'`info` has the wrong type: Received `{type(params.get("info", False))}` expected `bool`')
    if params.get("quiet", False) is None:
        raise StyxValidationError("`quiet` must not be None")
    if not isinstance(params["quiet"], bool):
        raise StyxValidationError(f'`quiet` has the wrong type: Received `{type(params.get("quiet", False))}` expected `bool`')
    if params.get("debug", False) is None:
        raise StyxValidationError("`debug` must not be None")
    if not isinstance(params["debug"], bool):
        raise StyxValidationError(f'`debug` has the wrong type: Received `{type(params.get("debug", False))}` expected `bool`')
    if params.get("force", False) is None:
        raise StyxValidationError("`force` must not be None")
    if not isinstance(params["force"], bool):
        raise StyxValidationError(f'`force` has the wrong type: Received `{type(params.get("force", False))}` expected `bool`')
    if params.get("nthreads", None) is not None:
        if not isinstance(params["nthreads"], int):
            raise StyxValidationError(f'`nthreads` has the wrong type: Received `{type(params.get("nthreads", None))}` expected `int | None`')
    if params.get("config", None) is not None:
        if not isinstance(params["config"], list):
            raise StyxValidationError(f'`config` has the wrong type: Received `{type(params.get("config", None))}` expected `list[Warp2metricConfigParamsDict] | None`')
        for e in params["config"]:
            warp2metric_config_validate(e)
    if params.get("help", False) is None:
        raise StyxValidationError("`help` must not be None")
    if not isinstance(params["help"], bool):
        raise StyxValidationError(f'`help` has the wrong type: Received `{type(params.get("help", False))}` expected `bool`')
    if params.get("version", False) is None:
        raise StyxValidationError("`version` must not be None")
    if not isinstance(params["version"], bool):
        raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", False))}` expected `bool`')
    if params.get("in", None) is None:
        raise StyxValidationError("`in` must not be None")
    if not isinstance(params["in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`in` has the wrong type: Received `{type(params.get("in", None))}` expected `InputPathType`')


def warp2metric_cargs(
    params: Warp2metricParamsDict,
    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("warp2metric")
    if params.get("fc", None) is not None:
        cargs.extend(warp2metric_fc_cargs(params.get("fc", None), execution))
    if params.get("jmat", None) is not None:
        cargs.extend([
            "-jmat",
            params.get("jmat", None)
        ])
    if params.get("jdet", None) is not None:
        cargs.extend([
            "-jdet",
            params.get("jdet", None)
        ])
    if params.get("info", False):
        cargs.append("-info")
    if params.get("quiet", False):
        cargs.append("-quiet")
    if params.get("debug", False):
        cargs.append("-debug")
    if params.get("force", False):
        cargs.append("-force")
    if params.get("nthreads", None) is not None:
        cargs.extend([
            "-nthreads",
            str(params.get("nthreads", None))
        ])
    if params.get("config", None) is not None:
        cargs.extend([a for c in [warp2metric_config_cargs(s, execution) for s in params.get("config", None)] for a in c])
    if params.get("help", False):
        cargs.append("-help")
    if params.get("version", False):
        cargs.append("-version")
    cargs.append(execution.input_file(params.get("in", None)))
    return cargs


def warp2metric_outputs(
    params: Warp2metricParamsDict,
    execution: Execution,
) -> Warp2metricOutputs:
    """
    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 = Warp2metricOutputs(
        root=execution.output_file("."),
        jmat=execution.output_file(params.get("jmat", None)) if (params.get("jmat") is not None) else None,
        jdet=execution.output_file(params.get("jdet", None)) if (params.get("jdet") is not None) else None,
    )
    return ret


def warp2metric_execute(
    params: Warp2metricParamsDict,
    runner: Runner | None = None,
) -> Warp2metricOutputs:
    """
    warp2metric
    
    Compute fixel-wise or voxel-wise metrics from a 4D deformation field.
    
    
    
    References:
    
    Raffelt, D.; Tournier, JD/; Smith, RE.; Vaughan, DN.; Jackson, G.; Ridgway,
    GR. Connelly, A.Investigating White Matter Fibre Density and Morphology
    using Fixel-Based Analysis. Neuroimage, 2017, 144, 58-73, doi:
    10.1016/j.neuroimage.2016.09.029.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Warp2metricOutputs`).
    """
    warp2metric_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(WARP2METRIC_METADATA)
    params = execution.params(params)
    cargs = warp2metric_cargs(params, execution)
    ret = warp2metric_outputs(params, execution)
    execution.run(cargs)
    return ret


def warp2metric(
    in_: InputPathType,
    fc: Warp2metricFcParamsDict | None = None,
    jmat: str | None = None,
    jdet: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Warp2metricConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> Warp2metricOutputs:
    """
    warp2metric
    
    Compute fixel-wise or voxel-wise metrics from a 4D deformation field.
    
    
    
    References:
    
    Raffelt, D.; Tournier, JD/; Smith, RE.; Vaughan, DN.; Jackson, G.; Ridgway,
    GR. Connelly, A.Investigating White Matter Fibre Density and Morphology
    using Fixel-Based Analysis. Neuroimage, 2017, 144, 58-73, doi:
    10.1016/j.neuroimage.2016.09.029.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        in_: the input deformation field.
        fc: use an input template fixel image to define fibre orientations and\
            output a fixel image describing the change in fibre cross-section (FC)\
            in the perpendicular plane to the fixel orientation. e.g. warp2metric\
            warp.mif -fc fixel_template_directory output_fixel_directory fc.mif.
        jmat: output a Jacobian matrix image stored in column-major order along\
            the 4th dimension.Note the output jacobian describes the warp gradient\
            w.r.t the scanner space coordinate system.
        jdet: output the Jacobian determinant instead of the full matrix.
        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 `Warp2metricOutputs`).
    """
    params = warp2metric_params(
        fc=fc,
        jmat=jmat,
        jdet=jdet,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        in_=in_,
    )
    return warp2metric_execute(params, runner)


__all__ = [
    "WARP2METRIC_METADATA",
    "Warp2metricConfigParamsDict",
    "Warp2metricConfigParamsDictTagged",
    "Warp2metricFcParamsDict",
    "Warp2metricFcParamsDictTagged",
    "Warp2metricOutputs",
    "Warp2metricParamsDict",
    "Warp2metricParamsDictTagged",
    "warp2metric",
    "warp2metric_config",
    "warp2metric_execute",
    "warp2metric_fc",
    "warp2metric_params",
]
