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

import typing
import pathlib
from styxdefs import *

AMP2SH_METADATA = Metadata(
    id="b1deae186542fe482c4a2e51622f124fe000c4fc.boutiques",
    name="amp2sh",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_Amp2shFslgradParamsDictNoTag = typing.TypedDict('_Amp2shFslgradParamsDictNoTag', {
    "bvecs": InputPathType,
    "bvals": InputPathType,
})
Amp2shFslgradParamsDictTagged = typing.TypedDict('Amp2shFslgradParamsDictTagged', {
    "@type": typing.Literal["fslgrad"],
    "bvecs": InputPathType,
    "bvals": InputPathType,
})
Amp2shFslgradParamsDict = _Amp2shFslgradParamsDictNoTag | Amp2shFslgradParamsDictTagged


_Amp2shVariousStringParamsDictNoTag = typing.TypedDict('_Amp2shVariousStringParamsDictNoTag', {
    "obj": str,
})
Amp2shVariousStringParamsDictTagged = typing.TypedDict('Amp2shVariousStringParamsDictTagged', {
    "@type": typing.Literal["VariousString"],
    "obj": str,
})
Amp2shVariousStringParamsDict = _Amp2shVariousStringParamsDictNoTag | Amp2shVariousStringParamsDictTagged


_Amp2shVariousFileParamsDictNoTag = typing.TypedDict('_Amp2shVariousFileParamsDictNoTag', {
    "obj": InputPathType,
})
Amp2shVariousFileParamsDictTagged = typing.TypedDict('Amp2shVariousFileParamsDictTagged', {
    "@type": typing.Literal["VariousFile"],
    "obj": InputPathType,
})
Amp2shVariousFileParamsDict = _Amp2shVariousFileParamsDictNoTag | Amp2shVariousFileParamsDictTagged


_Amp2shConfigParamsDictNoTag = typing.TypedDict('_Amp2shConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
Amp2shConfigParamsDictTagged = typing.TypedDict('Amp2shConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
Amp2shConfigParamsDict = _Amp2shConfigParamsDictNoTag | Amp2shConfigParamsDictTagged


_Amp2shParamsDictNoTag = typing.TypedDict('_Amp2shParamsDictNoTag', {
    "lmax": typing.NotRequired[int | None],
    "normalise": bool,
    "directions": typing.NotRequired[InputPathType | None],
    "rician": typing.NotRequired[InputPathType | None],
    "grad": typing.NotRequired[InputPathType | None],
    "fslgrad": typing.NotRequired[Amp2shFslgradParamsDict | None],
    "shells": typing.NotRequired[list[float] | None],
    "strides": typing.NotRequired[typing.Union[Amp2shVariousStringParamsDictTagged, Amp2shVariousFileParamsDictTagged] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Amp2shConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "amp": InputPathType,
    "SH": str,
})
Amp2shParamsDictTagged = typing.TypedDict('Amp2shParamsDictTagged', {
    "@type": typing.Literal["mrtrix/amp2sh"],
    "lmax": typing.NotRequired[int | None],
    "normalise": bool,
    "directions": typing.NotRequired[InputPathType | None],
    "rician": typing.NotRequired[InputPathType | None],
    "grad": typing.NotRequired[InputPathType | None],
    "fslgrad": typing.NotRequired[Amp2shFslgradParamsDict | None],
    "shells": typing.NotRequired[list[float] | None],
    "strides": typing.NotRequired[typing.Union[Amp2shVariousStringParamsDictTagged, Amp2shVariousFileParamsDictTagged] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Amp2shConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "amp": InputPathType,
    "SH": str,
})
Amp2shParamsDict = _Amp2shParamsDictNoTag | Amp2shParamsDictTagged


def amp2sh_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": amp2sh_various_string_cargs,
        "VariousFile": amp2sh_various_file_cargs,
    }.get(t)


def amp2sh_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": amp2sh_various_string_validate,
        "VariousFile": amp2sh_various_file_validate,
    }.get(t)


def amp2sh_fslgrad(
    bvecs: InputPathType,
    bvals: InputPathType,
) -> Amp2shFslgradParamsDictTagged:
    """
    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 amp2sh_fslgrad_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Amp2shFslgradParamsDict` 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 amp2sh_fslgrad_cargs(
    params: Amp2shFslgradParamsDict,
    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 amp2sh_various_string(
    obj: str,
) -> Amp2shVariousStringParamsDictTagged:
    """
    Build parameters.
    
    Args:
        obj: String object.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "VariousString",
        "obj": obj,
    }
    return params


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


def amp2sh_various_file_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Amp2shVariousFileParamsDict` 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 amp2sh_various_file_cargs(
    params: Amp2shVariousFileParamsDict,
    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 amp2sh_config(
    key: str,
    value: str,
) -> Amp2shConfigParamsDictTagged:
    """
    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 amp2sh_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Amp2shConfigParamsDict` 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 amp2sh_config_cargs(
    params: Amp2shConfigParamsDict,
    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 Amp2shOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Amp2shParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    sh: OutputPathType
    """the output spherical harmonics coefficients image."""


def amp2sh_params(
    amp: InputPathType,
    sh: str,
    lmax: int | None = None,
    normalise: bool = False,
    directions: InputPathType | None = None,
    rician: InputPathType | None = None,
    grad: InputPathType | None = None,
    fslgrad: Amp2shFslgradParamsDict | None = None,
    shells: list[float] | None = None,
    strides: typing.Union[Amp2shVariousStringParamsDictTagged, Amp2shVariousFileParamsDictTagged] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Amp2shConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> Amp2shParamsDictTagged:
    """
    Build parameters.
    
    Args:
        amp: the input amplitude image.
        sh: the output spherical harmonics coefficients image.
        lmax: set the maximum harmonic order for the output series. By default,\
            the program will use the highest possible lmax given the number of\
            diffusion-weighted images, up to a maximum of 8.
        normalise: normalise the DW signal to the b=0 image.
        directions: the directions corresponding to the input amplitude image\
            used to sample AFD. By default this option is not required providing\
            the direction set is supplied in the amplitude image. This should be\
            supplied as a list of directions [az el], as generated using the dirgen\
            command, or as a list of [ x y z ] Cartesian coordinates.
        rician: correct for Rician noise induced bias, using noise map supplied.
        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.
        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/amp2sh",
        "normalise": normalise,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "amp": amp,
        "SH": sh,
    }
    if lmax is not None:
        params["lmax"] = lmax
    if directions is not None:
        params["directions"] = directions
    if rician is not None:
        params["rician"] = rician
    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 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 amp2sh_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Amp2shParamsDict` 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("lmax", None) is not None:
        if not isinstance(params["lmax"], int):
            raise StyxValidationError(f'`lmax` has the wrong type: Received `{type(params.get("lmax", None))}` expected `int | None`')
    if params.get("normalise", False) is None:
        raise StyxValidationError("`normalise` must not be None")
    if not isinstance(params["normalise"], bool):
        raise StyxValidationError(f'`normalise` has the wrong type: Received `{type(params.get("normalise", False))}` expected `bool`')
    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("rician", None) is not None:
        if not isinstance(params["rician"], (pathlib.Path, str)):
            raise StyxValidationError(f'`rician` has the wrong type: Received `{type(params.get("rician", None))}` expected `InputPathType | None`')
    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:
        amp2sh_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("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\"]")
        amp2sh_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[Amp2shConfigParamsDict] | None`')
        for e in params["config"]:
            amp2sh_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("amp", None) is None:
        raise StyxValidationError("`amp` must not be None")
    if not isinstance(params["amp"], (pathlib.Path, str)):
        raise StyxValidationError(f'`amp` has the wrong type: Received `{type(params.get("amp", None))}` expected `InputPathType`')
    if params.get("SH", None) is None:
        raise StyxValidationError("`SH` must not be None")
    if not isinstance(params["SH"], str):
        raise StyxValidationError(f'`SH` has the wrong type: Received `{type(params.get("SH", None))}` expected `str`')


def amp2sh_cargs(
    params: Amp2shParamsDict,
    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("amp2sh")
    if params.get("lmax", None) is not None:
        cargs.extend([
            "-lmax",
            str(params.get("lmax", None))
        ])
    if params.get("normalise", False):
        cargs.append("-normalise")
    if params.get("directions", None) is not None:
        cargs.extend([
            "-directions",
            execution.input_file(params.get("directions", None))
        ])
    if params.get("rician", None) is not None:
        cargs.extend([
            "-rician",
            execution.input_file(params.get("rician", None))
        ])
    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(amp2sh_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("strides", None) is not None:
        cargs.extend([
            "-strides",
            *amp2sh_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 [amp2sh_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("amp", None)))
    cargs.append(params.get("SH", None))
    return cargs


def amp2sh_outputs(
    params: Amp2shParamsDict,
    execution: Execution,
) -> Amp2shOutputs:
    """
    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 = Amp2shOutputs(
        root=execution.output_file("."),
        sh=execution.output_file(params.get("SH", None)),
    )
    return ret


def amp2sh_execute(
    params: Amp2shParamsDict,
    runner: Runner | None = None,
) -> Amp2shOutputs:
    """
    amp2sh
    
    Convert a set of amplitudes (defined along a set of corresponding
    directions) to their spherical harmonic representation.
    
    The spherical harmonic decomposition is calculated by least-squares linear
    fitting to the amplitude data.
    
    The directions can be defined either as a DW gradient scheme (for example to
    compute the SH representation of the DW signal), a set of [az el] pairs as
    output by the dirgen command, or a set of [ x y z ] directions in Cartesian
    coordinates. The DW gradient scheme or direction set can be supplied within
    the input image header or using the -gradient or -directions option. Note
    that if a direction set and DW gradient scheme can be found, the direction
    set will be used by default.
    
    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:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Amp2shOutputs`).
    """
    amp2sh_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(AMP2SH_METADATA)
    params = execution.params(params)
    cargs = amp2sh_cargs(params, execution)
    ret = amp2sh_outputs(params, execution)
    execution.run(cargs)
    return ret


def amp2sh(
    amp: InputPathType,
    sh: str,
    lmax: int | None = None,
    normalise: bool = False,
    directions: InputPathType | None = None,
    rician: InputPathType | None = None,
    grad: InputPathType | None = None,
    fslgrad: Amp2shFslgradParamsDict | None = None,
    shells: list[float] | None = None,
    strides: typing.Union[Amp2shVariousStringParamsDictTagged, Amp2shVariousFileParamsDictTagged] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Amp2shConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> Amp2shOutputs:
    """
    amp2sh
    
    Convert a set of amplitudes (defined along a set of corresponding
    directions) to their spherical harmonic representation.
    
    The spherical harmonic decomposition is calculated by least-squares linear
    fitting to the amplitude data.
    
    The directions can be defined either as a DW gradient scheme (for example to
    compute the SH representation of the DW signal), a set of [az el] pairs as
    output by the dirgen command, or a set of [ x y z ] directions in Cartesian
    coordinates. The DW gradient scheme or direction set can be supplied within
    the input image header or using the -gradient or -directions option. Note
    that if a direction set and DW gradient scheme can be found, the direction
    set will be used by default.
    
    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:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        amp: the input amplitude image.
        sh: the output spherical harmonics coefficients image.
        lmax: set the maximum harmonic order for the output series. By default,\
            the program will use the highest possible lmax given the number of\
            diffusion-weighted images, up to a maximum of 8.
        normalise: normalise the DW signal to the b=0 image.
        directions: the directions corresponding to the input amplitude image\
            used to sample AFD. By default this option is not required providing\
            the direction set is supplied in the amplitude image. This should be\
            supplied as a list of directions [az el], as generated using the dirgen\
            command, or as a list of [ x y z ] Cartesian coordinates.
        rician: correct for Rician noise induced bias, using noise map supplied.
        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.
        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 `Amp2shOutputs`).
    """
    params = amp2sh_params(
        lmax=lmax,
        normalise=normalise,
        directions=directions,
        rician=rician,
        grad=grad,
        fslgrad=fslgrad,
        shells=shells,
        strides=strides,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        amp=amp,
        sh=sh,
    )
    return amp2sh_execute(params, runner)


__all__ = [
    "AMP2SH_METADATA",
    "Amp2shConfigParamsDict",
    "Amp2shConfigParamsDictTagged",
    "Amp2shFslgradParamsDict",
    "Amp2shFslgradParamsDictTagged",
    "Amp2shOutputs",
    "Amp2shParamsDict",
    "Amp2shParamsDictTagged",
    "Amp2shVariousFileParamsDict",
    "Amp2shVariousFileParamsDictTagged",
    "Amp2shVariousStringParamsDict",
    "Amp2shVariousStringParamsDictTagged",
    "amp2sh",
    "amp2sh_config",
    "amp2sh_execute",
    "amp2sh_fslgrad",
    "amp2sh_params",
    "amp2sh_various_file",
    "amp2sh_various_string",
]
