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

import typing
import pathlib
from styxdefs import *

KELLY_KAPOWSKI_METADATA = Metadata(
    id="8cf867e1228b8566e73919051e43b36f34a80495.boutiques",
    name="KellyKapowski",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


KellyKapowskiParameters = typing.TypedDict('KellyKapowskiParameters', {
    "__STYX_TYPE__": typing.Literal["KellyKapowski"],
    "image_dimensionality": typing.NotRequired[typing.Literal[2, 3] | None],
    "segmentation_image": typing.NotRequired[InputPathType | None],
    "gray_matter_probability_image": typing.NotRequired[InputPathType | None],
    "white_matter_probability_image": typing.NotRequired[InputPathType | None],
    "convergence": typing.NotRequired[str | None],
    "thickness_prior_estimate": typing.NotRequired[float | None],
    "thickness_prior_image": typing.NotRequired[InputPathType | None],
    "gradient_step": typing.NotRequired[float | None],
    "smoothing_variance": typing.NotRequired[float | None],
    "smoothing_velocity_field_parameter": typing.NotRequired[str | None],
    "use_bspline_smoothing": typing.NotRequired[typing.Literal[0, 1] | None],
    "use_masked_smoothing": typing.NotRequired[typing.Literal[0, 1] | None],
    "time_points": typing.NotRequired[str | None],
    "restrict_deformation": typing.NotRequired[typing.Literal[0, 1] | None],
    "number_of_integration_points": typing.NotRequired[int | None],
    "maximum_number_of_invert_displacement_field_iterations": typing.NotRequired[int | None],
    "output": str,
    "verbose": typing.NotRequired[typing.Literal[0, 1] | None],
})


def dyn_cargs(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "KellyKapowski": kelly_kapowski_cargs,
    }.get(t)


def dyn_outputs(
    t: str,
) -> typing.Any:
    """
    Get build outputs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build outputs function.
    """
    return {
        "KellyKapowski": kelly_kapowski_outputs,
    }.get(t)


class KellyKapowskiOutputs(typing.NamedTuple):
    """
    Output object returned when calling `kelly_kapowski(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    thickness_map: OutputPathType
    """The output is the thickness map defined in the segmented gray matter."""


def kelly_kapowski_params(
    output: str,
    image_dimensionality: typing.Literal[2, 3] | None = None,
    segmentation_image: InputPathType | None = None,
    gray_matter_probability_image: InputPathType | None = None,
    white_matter_probability_image: InputPathType | None = None,
    convergence: str | None = None,
    thickness_prior_estimate: float | None = None,
    thickness_prior_image: InputPathType | None = None,
    gradient_step: float | None = None,
    smoothing_variance: float | None = None,
    smoothing_velocity_field_parameter: str | None = None,
    use_bspline_smoothing: typing.Literal[0, 1] | None = None,
    use_masked_smoothing: typing.Literal[0, 1] | None = None,
    time_points: str | None = None,
    restrict_deformation: typing.Literal[0, 1] | None = None,
    number_of_integration_points: int | None = None,
    maximum_number_of_invert_displacement_field_iterations: int | None = None,
    verbose: typing.Literal[0, 1] | None = None,
) -> KellyKapowskiParameters:
    """
    Build parameters.
    
    Args:
        output: The output consists of a thickness map defined in the segmented\
            gray matter.
        image_dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, DiReCT tries to infer\
            the dimensionality from the input image.
        segmentation_image: A segmentation image must be supplied labeling the\
            gray and white matters. Default values = 2 and 3, respectively.
        gray_matter_probability_image: In addition to the segmentation image, a\
            gray matter probability image can be used. If no such image is\
            supplied, one is created using the segmentation image and a variance of\
            1.0 mm.
        white_matter_probability_image: In addition to the segmentation image,\
            a white matter probability image can be used. If no such image is\
            supplied, one is created using the segmentation image and a variance of\
            1.0 mm.
        convergence: Convergence is determined by fitting a line to the\
            normalized energy profile of the last N iterations (where N is\
            specified by the window size) and determining the slope which is then\
            compared with the convergence threshold.
        thickness_prior_estimate: Provides a prior constraint on the final\
            thickness measurement. Default = 10 mm.
        thickness_prior_image: An image containing spatially varying prior\
            thickness values.
        gradient_step: Gradient step size for the optimization. Default =\
            0.025.
        smoothing_variance: Defines the Gaussian smoothing of the hit and total\
            images. Default = 1.0 mm.
        smoothing_velocity_field_parameter: Defines the Gaussian smoothing of\
            the velocity field (default = 1.5 voxels). If the b-spline smoothing\
            option is chosen, then this defines the isotropic mesh spacing for the\
            smoothing spline (default = 15 mm).
        use_bspline_smoothing: Sets the option for B-spline smoothing of the\
            velocity field. Default = false.
        use_masked_smoothing: Sets the option for masked-based smoothing of the\
            velocity field. Default = false.
        time_points: Time points for irregularly spaced time samples and\
            time-variance with which to compute distance metric.
        restrict_deformation: Restrict the last dimension's deformation. Meant\
            for use with multiple time points. Default = false.
        number_of_integration_points: Number of compositions of the\
            diffeomorphism per iteration. Default = 10.
        maximum_number_of_invert_displacement_field_iterations: Maximum number\
            of iterations for estimating the invert displacement field. Default =\
            20.
        verbose: Verbose output.
    Returns:
        Parameter dictionary
    """
    params = {
        "__STYXTYPE__": "KellyKapowski",
        "output": output,
    }
    if image_dimensionality is not None:
        params["image_dimensionality"] = image_dimensionality
    if segmentation_image is not None:
        params["segmentation_image"] = segmentation_image
    if gray_matter_probability_image is not None:
        params["gray_matter_probability_image"] = gray_matter_probability_image
    if white_matter_probability_image is not None:
        params["white_matter_probability_image"] = white_matter_probability_image
    if convergence is not None:
        params["convergence"] = convergence
    if thickness_prior_estimate is not None:
        params["thickness_prior_estimate"] = thickness_prior_estimate
    if thickness_prior_image is not None:
        params["thickness_prior_image"] = thickness_prior_image
    if gradient_step is not None:
        params["gradient_step"] = gradient_step
    if smoothing_variance is not None:
        params["smoothing_variance"] = smoothing_variance
    if smoothing_velocity_field_parameter is not None:
        params["smoothing_velocity_field_parameter"] = smoothing_velocity_field_parameter
    if use_bspline_smoothing is not None:
        params["use_bspline_smoothing"] = use_bspline_smoothing
    if use_masked_smoothing is not None:
        params["use_masked_smoothing"] = use_masked_smoothing
    if time_points is not None:
        params["time_points"] = time_points
    if restrict_deformation is not None:
        params["restrict_deformation"] = restrict_deformation
    if number_of_integration_points is not None:
        params["number_of_integration_points"] = number_of_integration_points
    if maximum_number_of_invert_displacement_field_iterations is not None:
        params["maximum_number_of_invert_displacement_field_iterations"] = maximum_number_of_invert_displacement_field_iterations
    if verbose is not None:
        params["verbose"] = verbose
    return params


def kelly_kapowski_cargs(
    params: KellyKapowskiParameters,
    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("KellyKapowski")
    if params.get("image_dimensionality") is not None:
        cargs.extend([
            "--image-dimensionality",
            str(params.get("image_dimensionality"))
        ])
    if params.get("segmentation_image") is not None:
        cargs.extend([
            "--segmentation-image",
            execution.input_file(params.get("segmentation_image"))
        ])
    if params.get("gray_matter_probability_image") is not None:
        cargs.extend([
            "--gray-matter-probability-image",
            execution.input_file(params.get("gray_matter_probability_image"))
        ])
    if params.get("white_matter_probability_image") is not None:
        cargs.extend([
            "--white-matter-probability-image",
            execution.input_file(params.get("white_matter_probability_image"))
        ])
    if params.get("convergence") is not None:
        cargs.extend([
            "--convergence",
            params.get("convergence")
        ])
    if params.get("thickness_prior_estimate") is not None:
        cargs.extend([
            "--thickness-prior-estimate",
            str(params.get("thickness_prior_estimate"))
        ])
    if params.get("thickness_prior_image") is not None:
        cargs.extend([
            "--thickness-prior-image",
            execution.input_file(params.get("thickness_prior_image"))
        ])
    if params.get("gradient_step") is not None:
        cargs.extend([
            "--gradient-step",
            str(params.get("gradient_step"))
        ])
    if params.get("smoothing_variance") is not None:
        cargs.extend([
            "--smoothing-variance",
            str(params.get("smoothing_variance"))
        ])
    if params.get("smoothing_velocity_field_parameter") is not None:
        cargs.extend([
            "--smoothing-velocity-field-parameter",
            params.get("smoothing_velocity_field_parameter")
        ])
    if params.get("use_bspline_smoothing") is not None:
        cargs.extend([
            "--use-bspline-smoothing",
            str(params.get("use_bspline_smoothing"))
        ])
    if params.get("use_masked_smoothing") is not None:
        cargs.extend([
            "--use-masked-smoothing",
            str(params.get("use_masked_smoothing"))
        ])
    if params.get("time_points") is not None:
        cargs.extend([
            "--time-points",
            params.get("time_points")
        ])
    if params.get("restrict_deformation") is not None:
        cargs.extend([
            "--restrict-deformation",
            str(params.get("restrict_deformation"))
        ])
    if params.get("number_of_integration_points") is not None:
        cargs.extend([
            "--number-of-integration-points",
            str(params.get("number_of_integration_points"))
        ])
    if params.get("maximum_number_of_invert_displacement_field_iterations") is not None:
        cargs.extend([
            "--maximum-number-of-invert-displacement-field-iterations",
            str(params.get("maximum_number_of_invert_displacement_field_iterations"))
        ])
    cargs.extend([
        "--output",
        params.get("output")
    ])
    if params.get("verbose") is not None:
        cargs.extend([
            "--verbose",
            str(params.get("verbose"))
        ])
    return cargs


def kelly_kapowski_outputs(
    params: KellyKapowskiParameters,
    execution: Execution,
) -> KellyKapowskiOutputs:
    """
    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 = KellyKapowskiOutputs(
        root=execution.output_file("."),
        thickness_map=execution.output_file(params.get("output")),
    )
    return ret


def kelly_kapowski_execute(
    params: KellyKapowskiParameters,
    execution: Execution,
) -> KellyKapowskiOutputs:
    """
    DiReCT is a registration based estimate of cortical thickness. It was published
    in S. R. Das, B. B. Avants, M. Grossman, and J. C. Gee, Registration based
    cortical thickness measurement, Neuroimage 2009, 45:867--879.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        execution: The execution object.
    Returns:
        NamedTuple of outputs (described in `KellyKapowskiOutputs`).
    """
    params = execution.params(params)
    cargs = kelly_kapowski_cargs(params, execution)
    ret = kelly_kapowski_outputs(params, execution)
    execution.run(cargs)
    return ret


def kelly_kapowski(
    output: str,
    image_dimensionality: typing.Literal[2, 3] | None = None,
    segmentation_image: InputPathType | None = None,
    gray_matter_probability_image: InputPathType | None = None,
    white_matter_probability_image: InputPathType | None = None,
    convergence: str | None = None,
    thickness_prior_estimate: float | None = None,
    thickness_prior_image: InputPathType | None = None,
    gradient_step: float | None = None,
    smoothing_variance: float | None = None,
    smoothing_velocity_field_parameter: str | None = None,
    use_bspline_smoothing: typing.Literal[0, 1] | None = None,
    use_masked_smoothing: typing.Literal[0, 1] | None = None,
    time_points: str | None = None,
    restrict_deformation: typing.Literal[0, 1] | None = None,
    number_of_integration_points: int | None = None,
    maximum_number_of_invert_displacement_field_iterations: int | None = None,
    verbose: typing.Literal[0, 1] | None = None,
    runner: Runner | None = None,
) -> KellyKapowskiOutputs:
    """
    DiReCT is a registration based estimate of cortical thickness. It was published
    in S. R. Das, B. B. Avants, M. Grossman, and J. C. Gee, Registration based
    cortical thickness measurement, Neuroimage 2009, 45:867--879.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        output: The output consists of a thickness map defined in the segmented\
            gray matter.
        image_dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, DiReCT tries to infer\
            the dimensionality from the input image.
        segmentation_image: A segmentation image must be supplied labeling the\
            gray and white matters. Default values = 2 and 3, respectively.
        gray_matter_probability_image: In addition to the segmentation image, a\
            gray matter probability image can be used. If no such image is\
            supplied, one is created using the segmentation image and a variance of\
            1.0 mm.
        white_matter_probability_image: In addition to the segmentation image,\
            a white matter probability image can be used. If no such image is\
            supplied, one is created using the segmentation image and a variance of\
            1.0 mm.
        convergence: Convergence is determined by fitting a line to the\
            normalized energy profile of the last N iterations (where N is\
            specified by the window size) and determining the slope which is then\
            compared with the convergence threshold.
        thickness_prior_estimate: Provides a prior constraint on the final\
            thickness measurement. Default = 10 mm.
        thickness_prior_image: An image containing spatially varying prior\
            thickness values.
        gradient_step: Gradient step size for the optimization. Default =\
            0.025.
        smoothing_variance: Defines the Gaussian smoothing of the hit and total\
            images. Default = 1.0 mm.
        smoothing_velocity_field_parameter: Defines the Gaussian smoothing of\
            the velocity field (default = 1.5 voxels). If the b-spline smoothing\
            option is chosen, then this defines the isotropic mesh spacing for the\
            smoothing spline (default = 15 mm).
        use_bspline_smoothing: Sets the option for B-spline smoothing of the\
            velocity field. Default = false.
        use_masked_smoothing: Sets the option for masked-based smoothing of the\
            velocity field. Default = false.
        time_points: Time points for irregularly spaced time samples and\
            time-variance with which to compute distance metric.
        restrict_deformation: Restrict the last dimension's deformation. Meant\
            for use with multiple time points. Default = false.
        number_of_integration_points: Number of compositions of the\
            diffeomorphism per iteration. Default = 10.
        maximum_number_of_invert_displacement_field_iterations: Maximum number\
            of iterations for estimating the invert displacement field. Default =\
            20.
        verbose: Verbose output.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `KellyKapowskiOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(KELLY_KAPOWSKI_METADATA)
    params = kelly_kapowski_params(
        image_dimensionality=image_dimensionality,
        segmentation_image=segmentation_image,
        gray_matter_probability_image=gray_matter_probability_image,
        white_matter_probability_image=white_matter_probability_image,
        convergence=convergence,
        thickness_prior_estimate=thickness_prior_estimate,
        thickness_prior_image=thickness_prior_image,
        gradient_step=gradient_step,
        smoothing_variance=smoothing_variance,
        smoothing_velocity_field_parameter=smoothing_velocity_field_parameter,
        use_bspline_smoothing=use_bspline_smoothing,
        use_masked_smoothing=use_masked_smoothing,
        time_points=time_points,
        restrict_deformation=restrict_deformation,
        number_of_integration_points=number_of_integration_points,
        maximum_number_of_invert_displacement_field_iterations=maximum_number_of_invert_displacement_field_iterations,
        output=output,
        verbose=verbose,
    )
    return kelly_kapowski_execute(params, execution)


__all__ = [
    "KELLY_KAPOWSKI_METADATA",
    "KellyKapowskiOutputs",
    "KellyKapowskiParameters",
    "kelly_kapowski",
    "kelly_kapowski_params",
]
