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

import typing
import pathlib
from styxdefs import *

CIFTI_FALSE_CORRELATION_METADATA = Metadata(
    id="4934b43c48754a15f2680766bf60fde0c8338b6e.workbench",
    name="cifti-false-correlation",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiFalseCorrelationLeftSurfaceParamsDictNoTag = typing.TypedDict('_CiftiFalseCorrelationLeftSurfaceParamsDictNoTag', {
    "surface": InputPathType,
    "text-out": typing.NotRequired[str | None],
})
CiftiFalseCorrelationLeftSurfaceParamsDictTagged = typing.TypedDict('CiftiFalseCorrelationLeftSurfaceParamsDictTagged', {
    "@type": typing.Literal["left-surface"],
    "surface": InputPathType,
    "text-out": typing.NotRequired[str | None],
})
CiftiFalseCorrelationLeftSurfaceParamsDict = _CiftiFalseCorrelationLeftSurfaceParamsDictNoTag | CiftiFalseCorrelationLeftSurfaceParamsDictTagged


_CiftiFalseCorrelationRightSurfaceParamsDictNoTag = typing.TypedDict('_CiftiFalseCorrelationRightSurfaceParamsDictNoTag', {
    "surface": InputPathType,
    "text-out": typing.NotRequired[str | None],
})
CiftiFalseCorrelationRightSurfaceParamsDictTagged = typing.TypedDict('CiftiFalseCorrelationRightSurfaceParamsDictTagged', {
    "@type": typing.Literal["right-surface"],
    "surface": InputPathType,
    "text-out": typing.NotRequired[str | None],
})
CiftiFalseCorrelationRightSurfaceParamsDict = _CiftiFalseCorrelationRightSurfaceParamsDictNoTag | CiftiFalseCorrelationRightSurfaceParamsDictTagged


_CiftiFalseCorrelationCerebellumSurfaceParamsDictNoTag = typing.TypedDict('_CiftiFalseCorrelationCerebellumSurfaceParamsDictNoTag', {
    "surface": InputPathType,
    "text-out": typing.NotRequired[str | None],
})
CiftiFalseCorrelationCerebellumSurfaceParamsDictTagged = typing.TypedDict('CiftiFalseCorrelationCerebellumSurfaceParamsDictTagged', {
    "@type": typing.Literal["cerebellum-surface"],
    "surface": InputPathType,
    "text-out": typing.NotRequired[str | None],
})
CiftiFalseCorrelationCerebellumSurfaceParamsDict = _CiftiFalseCorrelationCerebellumSurfaceParamsDictNoTag | CiftiFalseCorrelationCerebellumSurfaceParamsDictTagged


_CiftiFalseCorrelationParamsDictNoTag = typing.TypedDict('_CiftiFalseCorrelationParamsDictNoTag', {
    "cifti-in": InputPathType,
    "3D-dist": float,
    "geo-outer": float,
    "geo-inner": float,
    "cifti-out": str,
    "left-surface": typing.NotRequired[CiftiFalseCorrelationLeftSurfaceParamsDict | None],
    "right-surface": typing.NotRequired[CiftiFalseCorrelationRightSurfaceParamsDict | None],
    "cerebellum-surface": typing.NotRequired[CiftiFalseCorrelationCerebellumSurfaceParamsDict | None],
})
CiftiFalseCorrelationParamsDictTagged = typing.TypedDict('CiftiFalseCorrelationParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-false-correlation"],
    "cifti-in": InputPathType,
    "3D-dist": float,
    "geo-outer": float,
    "geo-inner": float,
    "cifti-out": str,
    "left-surface": typing.NotRequired[CiftiFalseCorrelationLeftSurfaceParamsDict | None],
    "right-surface": typing.NotRequired[CiftiFalseCorrelationRightSurfaceParamsDict | None],
    "cerebellum-surface": typing.NotRequired[CiftiFalseCorrelationCerebellumSurfaceParamsDict | None],
})
CiftiFalseCorrelationParamsDict = _CiftiFalseCorrelationParamsDictNoTag | CiftiFalseCorrelationParamsDictTagged


def cifti_false_correlation_left_surface(
    surface: InputPathType,
    text_out: str | None = None,
) -> CiftiFalseCorrelationLeftSurfaceParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface: the left surface file.
        text_out: dump the raw measures used to a text file\
            \
            the output text file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "left-surface",
        "surface": surface,
    }
    if text_out is not None:
        params["text-out"] = text_out
    return params


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


def cifti_false_correlation_left_surface_cargs(
    params: CiftiFalseCorrelationLeftSurfaceParamsDict,
    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([
        "-left-surface",
        execution.input_file(params.get("surface", None))
    ])
    if params.get("text-out", None) is not None:
        cargs.extend([
            "-dump-text",
            params.get("text-out", None)
        ])
    return cargs


def cifti_false_correlation_right_surface(
    surface: InputPathType,
    text_out: str | None = None,
) -> CiftiFalseCorrelationRightSurfaceParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface: the right surface file.
        text_out: dump the raw measures used to a text file\
            \
            the output text file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "right-surface",
        "surface": surface,
    }
    if text_out is not None:
        params["text-out"] = text_out
    return params


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


def cifti_false_correlation_right_surface_cargs(
    params: CiftiFalseCorrelationRightSurfaceParamsDict,
    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([
        "-right-surface",
        execution.input_file(params.get("surface", None))
    ])
    if params.get("text-out", None) is not None:
        cargs.extend([
            "-dump-text",
            params.get("text-out", None)
        ])
    return cargs


def cifti_false_correlation_cerebellum_surface(
    surface: InputPathType,
    text_out: str | None = None,
) -> CiftiFalseCorrelationCerebellumSurfaceParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface: the cerebellum surface file.
        text_out: dump the raw measures used to a text file\
            \
            the output text file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "cerebellum-surface",
        "surface": surface,
    }
    if text_out is not None:
        params["text-out"] = text_out
    return params


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


def cifti_false_correlation_cerebellum_surface_cargs(
    params: CiftiFalseCorrelationCerebellumSurfaceParamsDict,
    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([
        "-cerebellum-surface",
        execution.input_file(params.get("surface", None))
    ])
    if params.get("text-out", None) is not None:
        cargs.extend([
            "-dump-text",
            params.get("text-out", None)
        ])
    return cargs


class CiftiFalseCorrelationOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiFalseCorrelationParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    cifti_out: OutputPathType
    """the output cifti dscalar file"""


def cifti_false_correlation_params(
    cifti_in: InputPathType,
    v_3_d_dist: float,
    geo_outer: float,
    geo_inner: float,
    cifti_out: str,
    left_surface: CiftiFalseCorrelationLeftSurfaceParamsDict | None = None,
    right_surface: CiftiFalseCorrelationRightSurfaceParamsDict | None = None,
    cerebellum_surface: CiftiFalseCorrelationCerebellumSurfaceParamsDict | None = None,
) -> CiftiFalseCorrelationParamsDictTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: the cifti file to use for correlation.
        v_3_d_dist: maximum 3D distance to check around each vertex.
        geo_outer: maximum geodesic distance to use for neighboring correlation.
        geo_inner: minimum geodesic distance to use for neighboring correlation.
        cifti_out: the output cifti dscalar file.
        left_surface: specify the left surface to use.
        right_surface: specify the right surface to use.
        cerebellum_surface: specify the cerebellum surface to use.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-false-correlation",
        "cifti-in": cifti_in,
        "3D-dist": v_3_d_dist,
        "geo-outer": geo_outer,
        "geo-inner": geo_inner,
        "cifti-out": cifti_out,
    }
    if left_surface is not None:
        params["left-surface"] = left_surface
    if right_surface is not None:
        params["right-surface"] = right_surface
    if cerebellum_surface is not None:
        params["cerebellum-surface"] = cerebellum_surface
    return params


def cifti_false_correlation_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiFalseCorrelationParamsDict` 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("cifti-in", None) is None:
        raise StyxValidationError("`cifti-in` must not be None")
    if not isinstance(params["cifti-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`cifti-in` has the wrong type: Received `{type(params.get("cifti-in", None))}` expected `InputPathType`')
    if params.get("3D-dist", None) is None:
        raise StyxValidationError("`3D-dist` must not be None")
    if not isinstance(params["3D-dist"], (float, int)):
        raise StyxValidationError(f'`3D-dist` has the wrong type: Received `{type(params.get("3D-dist", None))}` expected `float`')
    if params.get("geo-outer", None) is None:
        raise StyxValidationError("`geo-outer` must not be None")
    if not isinstance(params["geo-outer"], (float, int)):
        raise StyxValidationError(f'`geo-outer` has the wrong type: Received `{type(params.get("geo-outer", None))}` expected `float`')
    if params.get("geo-inner", None) is None:
        raise StyxValidationError("`geo-inner` must not be None")
    if not isinstance(params["geo-inner"], (float, int)):
        raise StyxValidationError(f'`geo-inner` has the wrong type: Received `{type(params.get("geo-inner", None))}` expected `float`')
    if params.get("cifti-out", None) is None:
        raise StyxValidationError("`cifti-out` must not be None")
    if not isinstance(params["cifti-out"], str):
        raise StyxValidationError(f'`cifti-out` has the wrong type: Received `{type(params.get("cifti-out", None))}` expected `str`')
    if params.get("left-surface", None) is not None:
        cifti_false_correlation_left_surface_validate(params["left-surface"])
    if params.get("right-surface", None) is not None:
        cifti_false_correlation_right_surface_validate(params["right-surface"])
    if params.get("cerebellum-surface", None) is not None:
        cifti_false_correlation_cerebellum_surface_validate(params["cerebellum-surface"])


def cifti_false_correlation_cargs(
    params: CiftiFalseCorrelationParamsDict,
    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",
        "-cifti-false-correlation"
    ])
    cargs.append(execution.input_file(params.get("cifti-in", None)))
    cargs.append(str(params.get("3D-dist", None)))
    cargs.append(str(params.get("geo-outer", None)))
    cargs.append(str(params.get("geo-inner", None)))
    cargs.append(params.get("cifti-out", None))
    if params.get("left-surface", None) is not None or params.get("right-surface", None) is not None or params.get("cerebellum-surface", None) is not None:
        cargs.extend([
            *(cifti_false_correlation_left_surface_cargs(params.get("left-surface", None), execution) if (params.get("left-surface", None) is not None) else []),
            *(cifti_false_correlation_right_surface_cargs(params.get("right-surface", None), execution) if (params.get("right-surface", None) is not None) else []),
            *(cifti_false_correlation_cerebellum_surface_cargs(params.get("cerebellum-surface", None), execution) if (params.get("cerebellum-surface", None) is not None) else [])
        ])
    return cargs


def cifti_false_correlation_outputs(
    params: CiftiFalseCorrelationParamsDict,
    execution: Execution,
) -> CiftiFalseCorrelationOutputs:
    """
    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 = CiftiFalseCorrelationOutputs(
        root=execution.output_file("."),
        cifti_out=execution.output_file(params.get("cifti-out", None)),
    )
    return ret


def cifti_false_correlation_execute(
    params: CiftiFalseCorrelationParamsDict,
    runner: Runner | None = None,
) -> CiftiFalseCorrelationOutputs:
    """
    COMPARE CORRELATION LOCALLY AND ACROSS/THROUGH SULCI/GYRI.
    
    For each vertex, compute the average correlation within a range of geodesic
    distances that don't cross a sulcus/gyrus, and the correlation to the
    closest vertex crossing a sulcus/gyrus. A vertex is considered to cross a
    sulcus/gyrus if the 3D distance is less than a third of the geodesic
    distance. The output file contains the ratio between these correlations, and
    some additional maps to help explain the ratio.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiFalseCorrelationOutputs`).
    """
    cifti_false_correlation_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_FALSE_CORRELATION_METADATA)
    params = execution.params(params)
    cargs = cifti_false_correlation_cargs(params, execution)
    ret = cifti_false_correlation_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_false_correlation(
    cifti_in: InputPathType,
    v_3_d_dist: float,
    geo_outer: float,
    geo_inner: float,
    cifti_out: str,
    left_surface: CiftiFalseCorrelationLeftSurfaceParamsDict | None = None,
    right_surface: CiftiFalseCorrelationRightSurfaceParamsDict | None = None,
    cerebellum_surface: CiftiFalseCorrelationCerebellumSurfaceParamsDict | None = None,
    runner: Runner | None = None,
) -> CiftiFalseCorrelationOutputs:
    """
    COMPARE CORRELATION LOCALLY AND ACROSS/THROUGH SULCI/GYRI.
    
    For each vertex, compute the average correlation within a range of geodesic
    distances that don't cross a sulcus/gyrus, and the correlation to the
    closest vertex crossing a sulcus/gyrus. A vertex is considered to cross a
    sulcus/gyrus if the 3D distance is less than a third of the geodesic
    distance. The output file contains the ratio between these correlations, and
    some additional maps to help explain the ratio.
    
    Args:
        cifti_in: the cifti file to use for correlation.
        v_3_d_dist: maximum 3D distance to check around each vertex.
        geo_outer: maximum geodesic distance to use for neighboring correlation.
        geo_inner: minimum geodesic distance to use for neighboring correlation.
        cifti_out: the output cifti dscalar file.
        left_surface: specify the left surface to use.
        right_surface: specify the right surface to use.
        cerebellum_surface: specify the cerebellum surface to use.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiFalseCorrelationOutputs`).
    """
    params = cifti_false_correlation_params(
        cifti_in=cifti_in,
        v_3_d_dist=v_3_d_dist,
        geo_outer=geo_outer,
        geo_inner=geo_inner,
        cifti_out=cifti_out,
        left_surface=left_surface,
        right_surface=right_surface,
        cerebellum_surface=cerebellum_surface,
    )
    return cifti_false_correlation_execute(params, runner)


__all__ = [
    "CIFTI_FALSE_CORRELATION_METADATA",
    "CiftiFalseCorrelationCerebellumSurfaceParamsDict",
    "CiftiFalseCorrelationCerebellumSurfaceParamsDictTagged",
    "CiftiFalseCorrelationLeftSurfaceParamsDict",
    "CiftiFalseCorrelationLeftSurfaceParamsDictTagged",
    "CiftiFalseCorrelationOutputs",
    "CiftiFalseCorrelationParamsDict",
    "CiftiFalseCorrelationParamsDictTagged",
    "CiftiFalseCorrelationRightSurfaceParamsDict",
    "CiftiFalseCorrelationRightSurfaceParamsDictTagged",
    "cifti_false_correlation",
    "cifti_false_correlation_cerebellum_surface",
    "cifti_false_correlation_execute",
    "cifti_false_correlation_left_surface",
    "cifti_false_correlation_params",
    "cifti_false_correlation_right_surface",
]
