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

import typing
import pathlib
from styxdefs import *

CONVERT_FIBER_ORIENTATIONS_METADATA = Metadata(
    id="c03f58871879950a5d06809f88add9efe24fe896.workbench",
    name="convert-fiber-orientations",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_ConvertFiberOrientationsFiberParamsDictNoTag = typing.TypedDict('_ConvertFiberOrientationsFiberParamsDictNoTag', {
    "mean-f": InputPathType,
    "stdev-f": InputPathType,
    "theta": InputPathType,
    "phi": InputPathType,
    "psi": InputPathType,
    "ka": InputPathType,
    "kb": InputPathType,
})
ConvertFiberOrientationsFiberParamsDictTagged = typing.TypedDict('ConvertFiberOrientationsFiberParamsDictTagged', {
    "@type": typing.Literal["fiber"],
    "mean-f": InputPathType,
    "stdev-f": InputPathType,
    "theta": InputPathType,
    "phi": InputPathType,
    "psi": InputPathType,
    "ka": InputPathType,
    "kb": InputPathType,
})
ConvertFiberOrientationsFiberParamsDict = _ConvertFiberOrientationsFiberParamsDictNoTag | ConvertFiberOrientationsFiberParamsDictTagged


_ConvertFiberOrientationsParamsDictNoTag = typing.TypedDict('_ConvertFiberOrientationsParamsDictNoTag', {
    "label-volume": InputPathType,
    "fiber-out": str,
    "fiber": typing.NotRequired[list[ConvertFiberOrientationsFiberParamsDict] | None],
})
ConvertFiberOrientationsParamsDictTagged = typing.TypedDict('ConvertFiberOrientationsParamsDictTagged', {
    "@type": typing.Literal["workbench/convert-fiber-orientations"],
    "label-volume": InputPathType,
    "fiber-out": str,
    "fiber": typing.NotRequired[list[ConvertFiberOrientationsFiberParamsDict] | None],
})
ConvertFiberOrientationsParamsDict = _ConvertFiberOrientationsParamsDictNoTag | ConvertFiberOrientationsParamsDictTagged


def convert_fiber_orientations_fiber(
    mean_f: InputPathType,
    stdev_f: InputPathType,
    theta: InputPathType,
    phi: InputPathType,
    psi: InputPathType,
    ka: InputPathType,
    kb: InputPathType,
) -> ConvertFiberOrientationsFiberParamsDictTagged:
    """
    Build parameters.
    
    Args:
        mean_f: mean fiber strength.
        stdev_f: standard deviation of fiber strength.
        theta: theta angle.
        phi: phi angle.
        psi: psi angle.
        ka: ka bingham parameter.
        kb: kb bingham parameter.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "fiber",
        "mean-f": mean_f,
        "stdev-f": stdev_f,
        "theta": theta,
        "phi": phi,
        "psi": psi,
        "ka": ka,
        "kb": kb,
    }
    return params


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


def convert_fiber_orientations_fiber_cargs(
    params: ConvertFiberOrientationsFiberParamsDict,
    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.extend([
        "-fiber",
        execution.input_file(params.get("mean-f", None)),
        execution.input_file(params.get("stdev-f", None)),
        execution.input_file(params.get("theta", None)),
        execution.input_file(params.get("phi", None)),
        execution.input_file(params.get("psi", None)),
        execution.input_file(params.get("ka", None)),
        execution.input_file(params.get("kb", None))
    ])
    return cargs


class ConvertFiberOrientationsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `ConvertFiberOrientationsParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    fiber_out: OutputPathType
    """the output fiber orientation file"""


def convert_fiber_orientations_params(
    label_volume: InputPathType,
    fiber_out: str,
    fiber: list[ConvertFiberOrientationsFiberParamsDict] | None = None,
) -> ConvertFiberOrientationsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        label_volume: volume of cifti structure labels.
        fiber_out: the output fiber orientation file.
        fiber: specify the parameter volumes for a fiber.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/convert-fiber-orientations",
        "label-volume": label_volume,
        "fiber-out": fiber_out,
    }
    if fiber is not None:
        params["fiber"] = fiber
    return params


def convert_fiber_orientations_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `ConvertFiberOrientationsParamsDict` 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("label-volume", None) is None:
        raise StyxValidationError("`label-volume` must not be None")
    if not isinstance(params["label-volume"], (pathlib.Path, str)):
        raise StyxValidationError(f'`label-volume` has the wrong type: Received `{type(params.get("label-volume", None))}` expected `InputPathType`')
    if params.get("fiber-out", None) is None:
        raise StyxValidationError("`fiber-out` must not be None")
    if not isinstance(params["fiber-out"], str):
        raise StyxValidationError(f'`fiber-out` has the wrong type: Received `{type(params.get("fiber-out", None))}` expected `str`')
    if params.get("fiber", None) is not None:
        if not isinstance(params["fiber"], list):
            raise StyxValidationError(f'`fiber` has the wrong type: Received `{type(params.get("fiber", None))}` expected `list[ConvertFiberOrientationsFiberParamsDict] | None`')
        for e in params["fiber"]:
            convert_fiber_orientations_fiber_validate(e)


def convert_fiber_orientations_cargs(
    params: ConvertFiberOrientationsParamsDict,
    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.extend([
        "wb_command",
        "-convert-fiber-orientations"
    ])
    cargs.append(execution.input_file(params.get("label-volume", None)))
    cargs.append(params.get("fiber-out", None))
    if params.get("fiber", None) is not None:
        cargs.extend([a for c in [convert_fiber_orientations_fiber_cargs(s, execution) for s in params.get("fiber", None)] for a in c])
    return cargs


def convert_fiber_orientations_outputs(
    params: ConvertFiberOrientationsParamsDict,
    execution: Execution,
) -> ConvertFiberOrientationsOutputs:
    """
    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 = ConvertFiberOrientationsOutputs(
        root=execution.output_file("."),
        fiber_out=execution.output_file(params.get("fiber-out", None)),
    )
    return ret


def convert_fiber_orientations_execute(
    params: ConvertFiberOrientationsParamsDict,
    runner: Runner | None = None,
) -> ConvertFiberOrientationsOutputs:
    """
    CONVERT BINGHAM PARAMETER VOLUMES TO FIBER ORIENTATION FILE.
    
    Takes precomputed bingham parameters from volume files and converts them to
    the format workbench uses for display. The <label-volume> argument must be a
    label volume, where the labels use these strings:
    
    
    CORTEX_LEFT
    CORTEX_RIGHT
    CEREBELLUM
    ACCUMBENS_LEFT
    ACCUMBENS_RIGHT
    ALL_GREY_MATTER
    ALL_WHITE_MATTER
    AMYGDALA_LEFT
    AMYGDALA_RIGHT
    BRAIN_STEM
    CAUDATE_LEFT
    CAUDATE_RIGHT
    CEREBELLAR_WHITE_MATTER_LEFT
    CEREBELLAR_WHITE_MATTER_RIGHT
    CEREBELLUM_LEFT
    CEREBELLUM_RIGHT
    CEREBRAL_WHITE_MATTER_LEFT
    CEREBRAL_WHITE_MATTER_RIGHT
    CORTEX
    DIENCEPHALON_VENTRAL_LEFT
    DIENCEPHALON_VENTRAL_RIGHT
    HIPPOCAMPUS_LEFT
    HIPPOCAMPUS_RIGHT
    HIPPOCAMPUS_DENTATE_LEFT
    HIPPOCAMPUS_DENTATE_RIGHT
    INVALID
    OTHER
    OTHER_GREY_MATTER
    OTHER_WHITE_MATTER
    PALLIDUM_LEFT
    PALLIDUM_RIGHT
    PUTAMEN_LEFT
    PUTAMEN_RIGHT
    THALAMUS_LEFT
    THALAMUS_RIGHT.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ConvertFiberOrientationsOutputs`).
    """
    convert_fiber_orientations_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CONVERT_FIBER_ORIENTATIONS_METADATA)
    params = execution.params(params)
    cargs = convert_fiber_orientations_cargs(params, execution)
    ret = convert_fiber_orientations_outputs(params, execution)
    execution.run(cargs)
    return ret


def convert_fiber_orientations(
    label_volume: InputPathType,
    fiber_out: str,
    fiber: list[ConvertFiberOrientationsFiberParamsDict] | None = None,
    runner: Runner | None = None,
) -> ConvertFiberOrientationsOutputs:
    """
    CONVERT BINGHAM PARAMETER VOLUMES TO FIBER ORIENTATION FILE.
    
    Takes precomputed bingham parameters from volume files and converts them to
    the format workbench uses for display. The <label-volume> argument must be a
    label volume, where the labels use these strings:
    
    
    CORTEX_LEFT
    CORTEX_RIGHT
    CEREBELLUM
    ACCUMBENS_LEFT
    ACCUMBENS_RIGHT
    ALL_GREY_MATTER
    ALL_WHITE_MATTER
    AMYGDALA_LEFT
    AMYGDALA_RIGHT
    BRAIN_STEM
    CAUDATE_LEFT
    CAUDATE_RIGHT
    CEREBELLAR_WHITE_MATTER_LEFT
    CEREBELLAR_WHITE_MATTER_RIGHT
    CEREBELLUM_LEFT
    CEREBELLUM_RIGHT
    CEREBRAL_WHITE_MATTER_LEFT
    CEREBRAL_WHITE_MATTER_RIGHT
    CORTEX
    DIENCEPHALON_VENTRAL_LEFT
    DIENCEPHALON_VENTRAL_RIGHT
    HIPPOCAMPUS_LEFT
    HIPPOCAMPUS_RIGHT
    HIPPOCAMPUS_DENTATE_LEFT
    HIPPOCAMPUS_DENTATE_RIGHT
    INVALID
    OTHER
    OTHER_GREY_MATTER
    OTHER_WHITE_MATTER
    PALLIDUM_LEFT
    PALLIDUM_RIGHT
    PUTAMEN_LEFT
    PUTAMEN_RIGHT
    THALAMUS_LEFT
    THALAMUS_RIGHT.
    
    Args:
        label_volume: volume of cifti structure labels.
        fiber_out: the output fiber orientation file.
        fiber: specify the parameter volumes for a fiber.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ConvertFiberOrientationsOutputs`).
    """
    params = convert_fiber_orientations_params(
        label_volume=label_volume,
        fiber_out=fiber_out,
        fiber=fiber,
    )
    return convert_fiber_orientations_execute(params, runner)


__all__ = [
    "CONVERT_FIBER_ORIENTATIONS_METADATA",
    "ConvertFiberOrientationsFiberParamsDict",
    "ConvertFiberOrientationsFiberParamsDictTagged",
    "ConvertFiberOrientationsOutputs",
    "ConvertFiberOrientationsParamsDict",
    "ConvertFiberOrientationsParamsDictTagged",
    "convert_fiber_orientations",
    "convert_fiber_orientations_execute",
    "convert_fiber_orientations_fiber",
    "convert_fiber_orientations_params",
]
