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

import typing
import pathlib
from styxdefs import *
import dataclasses

ATROPOS_METADATA = Metadata(
    id="4530aeaa8993b5f6c6337cb784311667ed8f0bbf.boutiques",
    name="Atropos",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


class AtroposOutputs(typing.NamedTuple):
    """
    Output object returned when calling `atropos(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    classified_image: OutputPathType
    """The output labeled image with assigned labels for each voxel in the
    masked region."""
    posterior_probability_images: OutputPathType
    """Output posterior probability images in specified format."""


def atropos(
    intensity_image: str,
    initialization: str,
    mask_image: InputPathType,
    convergence: str,
    likelihood_model: str,
    output: str,
    image_dimensionality: typing.Literal[2, 3, 4] | None = None,
    bspline: str | None = None,
    partial_volume_label_set: str | None = None,
    use_partial_volume_likelihoods: typing.Literal[0, 1] | None = None,
    posterior_formulation: str | None = None,
    mrf: str | None = None,
    icm: str | None = None,
    use_random_seed: typing.Literal[0, 1] | None = None,
    minimize_memory_usage: typing.Literal[0, 1] | None = None,
    winsorize_outliers: str | None = None,
    use_euclidean_distance: typing.Literal[0, 1] | None = None,
    label_propagation: str | None = None,
    verbose: typing.Literal[0, 1] | None = None,
    runner: Runner | None = None,
) -> AtroposOutputs:
    """
    Atropos is a finite mixture modeling (FMM) segmentation approach that allows for
    prior constraints including a prior label image, prior probability images,
    and/or an MRF prior to enforce spatial smoothing of the labels.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        intensity_image: One or more scalar images is specified for\
            segmentation. For scenarios with no prior information, the first scalar\
            image is used to order labelings by intensity. The optional adaptive\
            smoothing weight is applicable with prior images, specified between\
            [0,1].
        initialization: Initialize the FMM parameters. options include Random,\
            Otsu, KMeans, PriorProbabilityImages, and PriorLabelImage.
        mask_image: The required image mask defines the region to be labeled by\
            Atropos.
        convergence: Determine convergence based on mean maximum posterior\
            probability over region of interest.
        likelihood_model: Specify parametric or non-parametric likelihood\
            model. Options include Gaussian, HistogramParzenWindows,\
            ManifoldParzenWindows, among others.
        output: Output labeled image and optionally posterior probability\
            images.
        image_dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, Atropos tries to infer\
            the dimensionality from the first input image.
        bspline: Parameters for B-Spline. Adaptive smoothing is applied to\
            intensity images if smoothing weights > 0.
        partial_volume_label_set: Model mixtures of classes within single\
            voxels. Specify labels for each partial volume class.
        use_partial_volume_likelihoods: Whether to use partial volume\
            likelihoods. A value of 1 considers the partial volume class separate\
            from tissue classes.
        posterior_formulation: Specify posterior probability formulation.\
            Options are Socrates, Plato, Aristotle, or Sigmoid.
        mrf: Markov Random Field parameters to enforce spatial constraints on\
            segmentation.
        icm: ICM (Iterated Conditional Modes) parameters for asynchronous\
            updating.
        use_random_seed: Initialize with a random seed or a constant seed\
            number.
        minimize_memory_usage: Minimize memory usage by calculating images on\
            the fly and storing only non-negligible pixel values.
        winsorize_outliers: Options to remove effects of outliers in\
            calculations using methods like BoxPlot or GrubbsRosner.
        use_euclidean_distance: Propagate labels throughout the mask using a\
            distance transform.
        label_propagation: Control propagation of each prior label by specified\
            lambda and boundary probability.
        verbose: Verbose output.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AtroposOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(ATROPOS_METADATA)
    cargs = []
    cargs.append("Atropos")
    if image_dimensionality is not None:
        cargs.extend([
            "--image-dimensionality",
            str(image_dimensionality)
        ])
    cargs.extend([
        "-a",
        intensity_image
    ])
    if bspline is not None:
        cargs.extend([
            "-b",
            bspline
        ])
    cargs.extend([
        "-i",
        initialization
    ])
    if partial_volume_label_set is not None:
        cargs.extend([
            "-s",
            partial_volume_label_set
        ])
    if use_partial_volume_likelihoods is not None:
        cargs.extend([
            "--use-partial-volume-likelihoods",
            str(use_partial_volume_likelihoods)
        ])
    if posterior_formulation is not None:
        cargs.extend([
            "-p",
            posterior_formulation
        ])
    cargs.extend([
        "-x",
        execution.input_file(mask_image)
    ])
    cargs.extend([
        "-c",
        convergence
    ])
    cargs.extend([
        "-k",
        likelihood_model
    ])
    if mrf is not None:
        cargs.extend([
            "-m",
            mrf
        ])
    if icm is not None:
        cargs.extend([
            "-g",
            icm
        ])
    if use_random_seed is not None:
        cargs.extend([
            "-r",
            str(use_random_seed)
        ])
    cargs.extend([
        "-o",
        output
    ])
    if minimize_memory_usage is not None:
        cargs.extend([
            "-u",
            str(minimize_memory_usage)
        ])
    if winsorize_outliers is not None:
        cargs.extend([
            "-w",
            winsorize_outliers
        ])
    if use_euclidean_distance is not None:
        cargs.extend([
            "-e",
            str(use_euclidean_distance)
        ])
    if label_propagation is not None:
        cargs.extend([
            "-l",
            label_propagation
        ])
    if verbose is not None:
        cargs.extend([
            "-v",
            str(verbose)
        ])
    ret = AtroposOutputs(
        root=execution.output_file("."),
        classified_image=execution.output_file(output + "_classified.nii.gz"),
        posterior_probability_images=execution.output_file("[POSTERIOR_PROBABILITY_IMAGE_FILE_NAME_FORMAT]"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "ATROPOS_METADATA",
    "AtroposOutputs",
    "atropos",
]
