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

import typing
import pathlib
from styxdefs import *

MRGRID_METADATA = Metadata(
    id="62aab6d384f12d5080514505c5f5b4c9d7d75bc0.boutiques",
    name="mrgrid",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_MrgridAxisParamsDictNoTag = typing.TypedDict('_MrgridAxisParamsDictNoTag', {
    "index": int,
    "spec": str,
})
MrgridAxisParamsDictTagged = typing.TypedDict('MrgridAxisParamsDictTagged', {
    "@type": typing.Literal["axis"],
    "index": int,
    "spec": str,
})
MrgridAxisParamsDict = _MrgridAxisParamsDictNoTag | MrgridAxisParamsDictTagged


_MrgridVariousStringParamsDictNoTag = typing.TypedDict('_MrgridVariousStringParamsDictNoTag', {
    "obj": str,
})
MrgridVariousStringParamsDictTagged = typing.TypedDict('MrgridVariousStringParamsDictTagged', {
    "@type": typing.Literal["VariousString"],
    "obj": str,
})
MrgridVariousStringParamsDict = _MrgridVariousStringParamsDictNoTag | MrgridVariousStringParamsDictTagged


_MrgridVariousFileParamsDictNoTag = typing.TypedDict('_MrgridVariousFileParamsDictNoTag', {
    "obj": InputPathType,
})
MrgridVariousFileParamsDictTagged = typing.TypedDict('MrgridVariousFileParamsDictTagged', {
    "@type": typing.Literal["VariousFile"],
    "obj": InputPathType,
})
MrgridVariousFileParamsDict = _MrgridVariousFileParamsDictNoTag | MrgridVariousFileParamsDictTagged


_MrgridConfigParamsDictNoTag = typing.TypedDict('_MrgridConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
MrgridConfigParamsDictTagged = typing.TypedDict('MrgridConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
MrgridConfigParamsDict = _MrgridConfigParamsDictNoTag | MrgridConfigParamsDictTagged


_MrgridParamsDictNoTag = typing.TypedDict('_MrgridParamsDictNoTag', {
    "template": typing.NotRequired[InputPathType | None],
    "size": typing.NotRequired[list[int] | None],
    "voxel": typing.NotRequired[list[float] | None],
    "scale": typing.NotRequired[list[float] | None],
    "interp": typing.NotRequired[str | None],
    "oversample": typing.NotRequired[list[int] | None],
    "as": typing.NotRequired[InputPathType | None],
    "uniform": typing.NotRequired[int | None],
    "mask": typing.NotRequired[InputPathType | None],
    "crop_unbound": bool,
    "axis": typing.NotRequired[list[MrgridAxisParamsDict] | None],
    "all_axes": bool,
    "fill": typing.NotRequired[float | None],
    "strides": typing.NotRequired[typing.Union[MrgridVariousStringParamsDictTagged, MrgridVariousFileParamsDictTagged] | None],
    "datatype": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MrgridConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "operation": str,
    "output": str,
})
MrgridParamsDictTagged = typing.TypedDict('MrgridParamsDictTagged', {
    "@type": typing.Literal["mrtrix/mrgrid"],
    "template": typing.NotRequired[InputPathType | None],
    "size": typing.NotRequired[list[int] | None],
    "voxel": typing.NotRequired[list[float] | None],
    "scale": typing.NotRequired[list[float] | None],
    "interp": typing.NotRequired[str | None],
    "oversample": typing.NotRequired[list[int] | None],
    "as": typing.NotRequired[InputPathType | None],
    "uniform": typing.NotRequired[int | None],
    "mask": typing.NotRequired[InputPathType | None],
    "crop_unbound": bool,
    "axis": typing.NotRequired[list[MrgridAxisParamsDict] | None],
    "all_axes": bool,
    "fill": typing.NotRequired[float | None],
    "strides": typing.NotRequired[typing.Union[MrgridVariousStringParamsDictTagged, MrgridVariousFileParamsDictTagged] | None],
    "datatype": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MrgridConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "operation": str,
    "output": str,
})
MrgridParamsDict = _MrgridParamsDictNoTag | MrgridParamsDictTagged


def mrgrid_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": mrgrid_various_string_cargs,
        "VariousFile": mrgrid_various_file_cargs,
    }.get(t)


def mrgrid_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": mrgrid_various_string_validate,
        "VariousFile": mrgrid_various_file_validate,
    }.get(t)


def mrgrid_axis(
    index: int,
    spec: str,
) -> MrgridAxisParamsDictTagged:
    """
    Build parameters.
    
    Args:
        index: pad or crop the input image along the provided axis (defined by\
            index). The specifier argument defines the number of voxels added or\
            removed on the lower or upper end of the axis (-axis index\
            delta_lower,delta_upper) or acts as a voxel selection range (-axis\
            index start:stop). In both modes, values are relative to the input\
            image (overriding all other extent-specifying options). Negative delta\
            specifier values trigger the inverse operation (pad instead of crop and\
            vice versa) and negative range specifier trigger padding. Note that the\
            deprecated commands 'mrcrop' and 'mrpad' used range-based and\
            delta-based -axis indices, respectively.
        spec: pad or crop the input image along the provided axis (defined by\
            index). The specifier argument defines the number of voxels added or\
            removed on the lower or upper end of the axis (-axis index\
            delta_lower,delta_upper) or acts as a voxel selection range (-axis\
            index start:stop). In both modes, values are relative to the input\
            image (overriding all other extent-specifying options). Negative delta\
            specifier values trigger the inverse operation (pad instead of crop and\
            vice versa) and negative range specifier trigger padding. Note that the\
            deprecated commands 'mrcrop' and 'mrpad' used range-based and\
            delta-based -axis indices, respectively.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "axis",
        "index": index,
        "spec": spec,
    }
    return params


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


def mrgrid_axis_cargs(
    params: MrgridAxisParamsDict,
    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("-axis")
    cargs.append(str(params.get("index", None)))
    cargs.append(params.get("spec", None))
    return cargs


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


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


def mrgrid_various_file_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrgridVariousFileParamsDict` 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 mrgrid_various_file_cargs(
    params: MrgridVariousFileParamsDict,
    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 mrgrid_config(
    key: str,
    value: str,
) -> MrgridConfigParamsDictTagged:
    """
    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 mrgrid_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrgridConfigParamsDict` 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 mrgrid_config_cargs(
    params: MrgridConfigParamsDict,
    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 MrgridOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MrgridParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """the output image."""


def mrgrid_params(
    input_: InputPathType,
    operation: str,
    output: str,
    template: InputPathType | None = None,
    size: list[int] | None = None,
    voxel: list[float] | None = None,
    scale: list[float] | None = None,
    interp: str | None = None,
    oversample: list[int] | None = None,
    as_: InputPathType | None = None,
    uniform: int | None = None,
    mask: InputPathType | None = None,
    crop_unbound: bool = False,
    axis: list[MrgridAxisParamsDict] | None = None,
    all_axes: bool = False,
    fill: float | None = None,
    strides: typing.Union[MrgridVariousStringParamsDictTagged, MrgridVariousFileParamsDictTagged] | None = None,
    datatype: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrgridConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> MrgridParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: input image to be regridded.
        operation: the operation to be performed, one of: regrid, crop, pad.
        output: the output image.
        template: match the input image grid (voxel spacing, image size, header\
            transformation) to that of a reference image. The image resolution\
            relative to the template image can be changed with one of -size,\
            -voxel, -scale.
        size: define the size (number of voxels) in each spatial dimension for\
            the output image. This should be specified as a comma-separated list.
        voxel: define the new voxel size for the output image. This can be\
            specified either as a single value to be used for all spatial\
            dimensions, or as a comma-separated list of the size for each voxel\
            dimension.
        scale: scale the image resolution by the supplied factor. This can be\
            specified either as a single value to be used for all dimensions, or as\
            a comma-separated list of scale factors for each dimension.
        interp: set the interpolation method to use when reslicing (choices:\
            nearest, linear, cubic, sinc. Default: cubic).
        oversample: set the amount of over-sampling (in the target space) to\
            perform when regridding. This is particularly relevant when downsamping\
            a high-resolution image to a low-resolution image, to avoid aliasing\
            artefacts. This can consist of a single integer, or a comma-separated\
            list of 3 integers if different oversampling factors are desired along\
            the different axes. Default is determined from ratio of voxel\
            dimensions (disabled for nearest-neighbour interpolation).
        as_: pad or crop the input image on the upper bound to match the\
            specified reference image grid. This operation ignores differences in\
            image transformation between input and reference image.
        uniform: pad or crop the input image by a uniform number of voxels on\
            all sides.
        mask: crop the input image according to the spatial extent of a mask\
            image. The mask must share a common voxel grid with the input image but\
            differences in image transformations are ignored. Note that even though\
            only 3 dimensions are cropped when using a mask, the bounds are\
            computed by checking the extent for all dimensions. Note that by\
            default a gap of 1 voxel is left at all edges of the image to allow\
            valid trilinear interpolation. This gap can be modified with the\
            -uniform option but by default it does not extend beyond the FOV unless\
            -crop_unbound is used.
        crop_unbound: Allow padding beyond the original FOV when cropping.
        axis: pad or crop the input image along the provided axis (defined by\
            index). The specifier argument defines the number of voxels added or\
            removed on the lower or upper end of the axis (-axis index\
            delta_lower,delta_upper) or acts as a voxel selection range (-axis\
            index start:stop). In both modes, values are relative to the input\
            image (overriding all other extent-specifying options). Negative delta\
            specifier values trigger the inverse operation (pad instead of crop and\
            vice versa) and negative range specifier trigger padding. Note that the\
            deprecated commands 'mrcrop' and 'mrpad' used range-based and\
            delta-based -axis indices, respectively.
        all_axes: Crop or pad all, not just spatial axes.
        fill: Use number as the out of bounds value. nan, inf and -inf are\
            valid arguments. (Default: 0.0).
        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.
        datatype: specify output image data type. Valid choices are: float32,\
            float32le, float32be, float64, float64le, float64be, int64, uint64,\
            int64le, uint64le, int64be, uint64be, int32, uint32, int32le, uint32le,\
            int32be, uint32be, int16, uint16, int16le, uint16le, int16be, uint16be,\
            cfloat32, cfloat32le, cfloat32be, cfloat64, cfloat64le, cfloat64be,\
            int8, uint8, bit.
        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/mrgrid",
        "crop_unbound": crop_unbound,
        "all_axes": all_axes,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "input": input_,
        "operation": operation,
        "output": output,
    }
    if template is not None:
        params["template"] = template
    if size is not None:
        params["size"] = size
    if voxel is not None:
        params["voxel"] = voxel
    if scale is not None:
        params["scale"] = scale
    if interp is not None:
        params["interp"] = interp
    if oversample is not None:
        params["oversample"] = oversample
    if as_ is not None:
        params["as"] = as_
    if uniform is not None:
        params["uniform"] = uniform
    if mask is not None:
        params["mask"] = mask
    if axis is not None:
        params["axis"] = axis
    if fill is not None:
        params["fill"] = fill
    if strides is not None:
        params["strides"] = strides
    if datatype is not None:
        params["datatype"] = datatype
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def mrgrid_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrgridParamsDict` 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", None) is not None:
        if not isinstance(params["template"], (pathlib.Path, str)):
            raise StyxValidationError(f'`template` has the wrong type: Received `{type(params.get("template", None))}` expected `InputPathType | None`')
    if params.get("size", None) is not None:
        if not isinstance(params["size"], list):
            raise StyxValidationError(f'`size` has the wrong type: Received `{type(params.get("size", None))}` expected `list[int] | None`')
        for e in params["size"]:
            if not isinstance(e, int):
                raise StyxValidationError(f'`size` has the wrong type: Received `{type(params.get("size", None))}` expected `list[int] | None`')
    if params.get("voxel", None) is not None:
        if not isinstance(params["voxel"], list):
            raise StyxValidationError(f'`voxel` has the wrong type: Received `{type(params.get("voxel", None))}` expected `list[float] | None`')
        for e in params["voxel"]:
            if not isinstance(e, (float, int)):
                raise StyxValidationError(f'`voxel` has the wrong type: Received `{type(params.get("voxel", None))}` expected `list[float] | None`')
    if params.get("scale", None) is not None:
        if not isinstance(params["scale"], list):
            raise StyxValidationError(f'`scale` has the wrong type: Received `{type(params.get("scale", None))}` expected `list[float] | None`')
        for e in params["scale"]:
            if not isinstance(e, (float, int)):
                raise StyxValidationError(f'`scale` has the wrong type: Received `{type(params.get("scale", None))}` expected `list[float] | None`')
    if params.get("interp", None) is not None:
        if not isinstance(params["interp"], str):
            raise StyxValidationError(f'`interp` has the wrong type: Received `{type(params.get("interp", None))}` expected `str | None`')
    if params.get("oversample", None) is not None:
        if not isinstance(params["oversample"], list):
            raise StyxValidationError(f'`oversample` has the wrong type: Received `{type(params.get("oversample", None))}` expected `list[int] | None`')
        for e in params["oversample"]:
            if not isinstance(e, int):
                raise StyxValidationError(f'`oversample` has the wrong type: Received `{type(params.get("oversample", None))}` expected `list[int] | None`')
    if params.get("as", None) is not None:
        if not isinstance(params["as"], (pathlib.Path, str)):
            raise StyxValidationError(f'`as` has the wrong type: Received `{type(params.get("as", None))}` expected `InputPathType | None`')
    if params.get("uniform", None) is not None:
        if not isinstance(params["uniform"], int):
            raise StyxValidationError(f'`uniform` has the wrong type: Received `{type(params.get("uniform", None))}` expected `int | None`')
    if params.get("mask", None) is not None:
        if not isinstance(params["mask"], (pathlib.Path, str)):
            raise StyxValidationError(f'`mask` has the wrong type: Received `{type(params.get("mask", None))}` expected `InputPathType | None`')
    if params.get("crop_unbound", False) is None:
        raise StyxValidationError("`crop_unbound` must not be None")
    if not isinstance(params["crop_unbound"], bool):
        raise StyxValidationError(f'`crop_unbound` has the wrong type: Received `{type(params.get("crop_unbound", False))}` expected `bool`')
    if params.get("axis", None) is not None:
        if not isinstance(params["axis"], list):
            raise StyxValidationError(f'`axis` has the wrong type: Received `{type(params.get("axis", None))}` expected `list[MrgridAxisParamsDict] | None`')
        for e in params["axis"]:
            mrgrid_axis_validate(e)
    if params.get("all_axes", False) is None:
        raise StyxValidationError("`all_axes` must not be None")
    if not isinstance(params["all_axes"], bool):
        raise StyxValidationError(f'`all_axes` has the wrong type: Received `{type(params.get("all_axes", False))}` expected `bool`')
    if params.get("fill", None) is not None:
        if not isinstance(params["fill"], (float, int)):
            raise StyxValidationError(f'`fill` has the wrong type: Received `{type(params.get("fill", None))}` expected `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\"]")
        mrgrid_strides_validate_dyn_fn(params["strides"]["@type"])(params["strides"])
    if params.get("datatype", None) is not None:
        if not isinstance(params["datatype"], str):
            raise StyxValidationError(f'`datatype` has the wrong type: Received `{type(params.get("datatype", 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[MrgridConfigParamsDict] | None`')
        for e in params["config"]:
            mrgrid_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("operation", None) is None:
        raise StyxValidationError("`operation` must not be None")
    if not isinstance(params["operation"], str):
        raise StyxValidationError(f'`operation` has the wrong type: Received `{type(params.get("operation", None))}` expected `str`')
    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 mrgrid_cargs(
    params: MrgridParamsDict,
    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("mrgrid")
    if params.get("template", None) is not None:
        cargs.extend([
            "-template",
            execution.input_file(params.get("template", None))
        ])
    if params.get("size", None) is not None:
        cargs.extend([
            "-size",
            ",".join(map(str, params.get("size", None)))
        ])
    if params.get("voxel", None) is not None:
        cargs.extend([
            "-voxel",
            ",".join(map(str, params.get("voxel", None)))
        ])
    if params.get("scale", None) is not None:
        cargs.extend([
            "-scale",
            ",".join(map(str, params.get("scale", None)))
        ])
    if params.get("interp", None) is not None:
        cargs.extend([
            "-interp",
            params.get("interp", None)
        ])
    if params.get("oversample", None) is not None:
        cargs.extend([
            "-oversample",
            ",".join(map(str, params.get("oversample", None)))
        ])
    if params.get("as", None) is not None:
        cargs.extend([
            "-as",
            execution.input_file(params.get("as", None))
        ])
    if params.get("uniform", None) is not None:
        cargs.extend([
            "-uniform",
            str(params.get("uniform", None))
        ])
    if params.get("mask", None) is not None:
        cargs.extend([
            "-mask",
            execution.input_file(params.get("mask", None))
        ])
    if params.get("crop_unbound", False):
        cargs.append("-crop_unbound")
    if params.get("axis", None) is not None:
        cargs.extend([a for c in [mrgrid_axis_cargs(s, execution) for s in params.get("axis", None)] for a in c])
    if params.get("all_axes", False):
        cargs.append("-all_axes")
    if params.get("fill", None) is not None:
        cargs.extend([
            "-fill",
            str(params.get("fill", None))
        ])
    if params.get("strides", None) is not None:
        cargs.extend([
            "-strides",
            *mrgrid_strides_cargs_dyn_fn(params.get("strides", None)["@type"])(params.get("strides", None), execution)
        ])
    if params.get("datatype", None) is not None:
        cargs.extend([
            "-datatype",
            params.get("datatype", 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 [mrgrid_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("operation", None))
    cargs.append(params.get("output", None))
    return cargs


def mrgrid_outputs(
    params: MrgridParamsDict,
    execution: Execution,
) -> MrgridOutputs:
    """
    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 = MrgridOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
    )
    return ret


def mrgrid_execute(
    params: MrgridParamsDict,
    runner: Runner | None = None,
) -> MrgridOutputs:
    """
    mrgrid
    
    Modify the grid of an image without interpolation (cropping or padding) or
    by regridding to an image grid with modified orientation, location and or
    resolution. The image content remains in place in real world coordinates..
    
    - regrid: This operation performs changes of the voxel grid that require
    interpolation of the image such as changing the resolution or location and
    orientation of the voxel grid. If the image is down-sampled, the appropriate
    smoothing is automatically applied using Gaussian smoothing unless nearest
    neighbour interpolation is selected or oversample is changed explicitly. The
    resolution can only be changed for spatial dimensions.
    
    - crop: The image extent after cropping, can be specified either manually
    for each axis dimensions, or via a mask or reference image. The image can be
    cropped to the extent of a mask. This is useful for axially-acquired brain
    images, where the image size can be reduced by a factor of 2 by removing the
    empty space on either side of the brain. Note that cropping does not extend
    the image beyond the original FOV unless explicitly specified (via
    -crop_unbound or negative -axis extent).
    
    - pad: Analogously to cropping, padding increases the FOV of an image
    without image interpolation. Pad and crop can be performed simultaneously by
    specifying signed specifier argument values to the -axis option.
    
    This command encapsulates and extends the functionality of the superseded
    commands 'mrpad', 'mrcrop' and 'mrresize'. Note the difference in -axis
    convention used for 'mrcrop' and 'mrpad' (see -axis option description).
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MrgridOutputs`).
    """
    mrgrid_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRGRID_METADATA)
    params = execution.params(params)
    cargs = mrgrid_cargs(params, execution)
    ret = mrgrid_outputs(params, execution)
    execution.run(cargs)
    return ret


def mrgrid(
    input_: InputPathType,
    operation: str,
    output: str,
    template: InputPathType | None = None,
    size: list[int] | None = None,
    voxel: list[float] | None = None,
    scale: list[float] | None = None,
    interp: str | None = None,
    oversample: list[int] | None = None,
    as_: InputPathType | None = None,
    uniform: int | None = None,
    mask: InputPathType | None = None,
    crop_unbound: bool = False,
    axis: list[MrgridAxisParamsDict] | None = None,
    all_axes: bool = False,
    fill: float | None = None,
    strides: typing.Union[MrgridVariousStringParamsDictTagged, MrgridVariousFileParamsDictTagged] | None = None,
    datatype: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrgridConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> MrgridOutputs:
    """
    mrgrid
    
    Modify the grid of an image without interpolation (cropping or padding) or
    by regridding to an image grid with modified orientation, location and or
    resolution. The image content remains in place in real world coordinates..
    
    - regrid: This operation performs changes of the voxel grid that require
    interpolation of the image such as changing the resolution or location and
    orientation of the voxel grid. If the image is down-sampled, the appropriate
    smoothing is automatically applied using Gaussian smoothing unless nearest
    neighbour interpolation is selected or oversample is changed explicitly. The
    resolution can only be changed for spatial dimensions.
    
    - crop: The image extent after cropping, can be specified either manually
    for each axis dimensions, or via a mask or reference image. The image can be
    cropped to the extent of a mask. This is useful for axially-acquired brain
    images, where the image size can be reduced by a factor of 2 by removing the
    empty space on either side of the brain. Note that cropping does not extend
    the image beyond the original FOV unless explicitly specified (via
    -crop_unbound or negative -axis extent).
    
    - pad: Analogously to cropping, padding increases the FOV of an image
    without image interpolation. Pad and crop can be performed simultaneously by
    specifying signed specifier argument values to the -axis option.
    
    This command encapsulates and extends the functionality of the superseded
    commands 'mrpad', 'mrcrop' and 'mrresize'. Note the difference in -axis
    convention used for 'mrcrop' and 'mrpad' (see -axis option description).
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        input_: input image to be regridded.
        operation: the operation to be performed, one of: regrid, crop, pad.
        output: the output image.
        template: match the input image grid (voxel spacing, image size, header\
            transformation) to that of a reference image. The image resolution\
            relative to the template image can be changed with one of -size,\
            -voxel, -scale.
        size: define the size (number of voxels) in each spatial dimension for\
            the output image. This should be specified as a comma-separated list.
        voxel: define the new voxel size for the output image. This can be\
            specified either as a single value to be used for all spatial\
            dimensions, or as a comma-separated list of the size for each voxel\
            dimension.
        scale: scale the image resolution by the supplied factor. This can be\
            specified either as a single value to be used for all dimensions, or as\
            a comma-separated list of scale factors for each dimension.
        interp: set the interpolation method to use when reslicing (choices:\
            nearest, linear, cubic, sinc. Default: cubic).
        oversample: set the amount of over-sampling (in the target space) to\
            perform when regridding. This is particularly relevant when downsamping\
            a high-resolution image to a low-resolution image, to avoid aliasing\
            artefacts. This can consist of a single integer, or a comma-separated\
            list of 3 integers if different oversampling factors are desired along\
            the different axes. Default is determined from ratio of voxel\
            dimensions (disabled for nearest-neighbour interpolation).
        as_: pad or crop the input image on the upper bound to match the\
            specified reference image grid. This operation ignores differences in\
            image transformation between input and reference image.
        uniform: pad or crop the input image by a uniform number of voxels on\
            all sides.
        mask: crop the input image according to the spatial extent of a mask\
            image. The mask must share a common voxel grid with the input image but\
            differences in image transformations are ignored. Note that even though\
            only 3 dimensions are cropped when using a mask, the bounds are\
            computed by checking the extent for all dimensions. Note that by\
            default a gap of 1 voxel is left at all edges of the image to allow\
            valid trilinear interpolation. This gap can be modified with the\
            -uniform option but by default it does not extend beyond the FOV unless\
            -crop_unbound is used.
        crop_unbound: Allow padding beyond the original FOV when cropping.
        axis: pad or crop the input image along the provided axis (defined by\
            index). The specifier argument defines the number of voxels added or\
            removed on the lower or upper end of the axis (-axis index\
            delta_lower,delta_upper) or acts as a voxel selection range (-axis\
            index start:stop). In both modes, values are relative to the input\
            image (overriding all other extent-specifying options). Negative delta\
            specifier values trigger the inverse operation (pad instead of crop and\
            vice versa) and negative range specifier trigger padding. Note that the\
            deprecated commands 'mrcrop' and 'mrpad' used range-based and\
            delta-based -axis indices, respectively.
        all_axes: Crop or pad all, not just spatial axes.
        fill: Use number as the out of bounds value. nan, inf and -inf are\
            valid arguments. (Default: 0.0).
        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.
        datatype: specify output image data type. Valid choices are: float32,\
            float32le, float32be, float64, float64le, float64be, int64, uint64,\
            int64le, uint64le, int64be, uint64be, int32, uint32, int32le, uint32le,\
            int32be, uint32be, int16, uint16, int16le, uint16le, int16be, uint16be,\
            cfloat32, cfloat32le, cfloat32be, cfloat64, cfloat64le, cfloat64be,\
            int8, uint8, bit.
        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 `MrgridOutputs`).
    """
    params = mrgrid_params(
        template=template,
        size=size,
        voxel=voxel,
        scale=scale,
        interp=interp,
        oversample=oversample,
        as_=as_,
        uniform=uniform,
        mask=mask,
        crop_unbound=crop_unbound,
        axis=axis,
        all_axes=all_axes,
        fill=fill,
        strides=strides,
        datatype=datatype,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        input_=input_,
        operation=operation,
        output=output,
    )
    return mrgrid_execute(params, runner)


__all__ = [
    "MRGRID_METADATA",
    "MrgridAxisParamsDict",
    "MrgridAxisParamsDictTagged",
    "MrgridConfigParamsDict",
    "MrgridConfigParamsDictTagged",
    "MrgridOutputs",
    "MrgridParamsDict",
    "MrgridParamsDictTagged",
    "MrgridVariousFileParamsDict",
    "MrgridVariousFileParamsDictTagged",
    "MrgridVariousStringParamsDict",
    "MrgridVariousStringParamsDictTagged",
    "mrgrid",
    "mrgrid_axis",
    "mrgrid_config",
    "mrgrid_execute",
    "mrgrid_params",
    "mrgrid_various_file",
    "mrgrid_various_string",
]
