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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_LABEL2VOL_METADATA = Metadata(
    id="b8585b66c04f6292d2db0caedbd9f154b0b92bab.boutiques",
    name="mri_label2vol",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriLabel2volOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_label2vol(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_vol: OutputPathType
    """The output volume where each voxel has the label it's assigned to."""
    hits_vol: OutputPathType | None
    """The hit volume file showing number of hits per voxel."""
    label_stat_vol: OutputPathType | None
    """The label stat volume file."""


def mri_label2vol(
    template: InputPathType,
    output_volume: str,
    labels: list[str] | None = None,
    annotation: InputPathType | None = None,
    segmentation: InputPathType | None = None,
    registration: InputPathType | None = None,
    identity_flag: bool = False,
    fill_threshold: float | None = None,
    label_vox_vol: float | None = None,
    projection: str | None = None,
    subject: str | None = None,
    hemisphere: str | None = None,
    hits_volume: str | None = None,
    label_stat_volume: str | None = None,
    stat_threshold: float | None = None,
    offset: float | None = None,
    defects: str | None = None,
    native_vox2ras_flag: bool = False,
    runner: Runner | None = None,
) -> MriLabel2volOutputs:
    """
    Converts a label or a set of labels into a volume.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        template: Template volume; the output will have the same size and\
            geometry.
        output_volume: Output volume in which each voxel will have the number\
            of the label to which it is assigned.
        labels: Enter the name of the label file. For multiple labels, use\
            multiple --label flags.
        annotation: Surface annotation file. Use this to input annotations\
            directly.
        segmentation: Path to input segmentation.
        registration: tkregister-style registration matrix mapping LabelXYZ to\
            VolXYZ.
        identity_flag: Use the identity matrix as the registration.
        fill_threshold: Threshold for voxel fill; a value between 0 and 1.
        label_vox_vol: Volume of each label point; default is 1mm³.
        projection: Project the label along the surface normal. Type can be abs\
            or frac.
        subject: FREESURFER subject identifier; needed with --proj.
        hemisphere: Hemisphere to use for --proj or --annot. Legal values are\
            lh and rh.
        hits_volume: Hit volume, a multi-frame volume with one frame per label\
            showing the number of hits per voxel.
        label_stat_volume: Map the label stats field into the volume.
        stat_threshold: Only use label point where stat > thresh.
        offset: Add offset to the segmentation numbers.
        defects: Creates a segmentation volume of the surface defects.
        native_vox2ras_flag: Use native voxel-to-RAS transform instead of\
            tkregister-style.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriLabel2volOutputs`).
    """
    if fill_threshold is not None and not (0 <= fill_threshold <= 1): 
        raise ValueError(f"'fill_threshold' must be between 0 <= x <= 1 but was {fill_threshold}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_LABEL2VOL_METADATA)
    cargs = []
    cargs.append("mri_label2vol")
    if labels is not None:
        cargs.extend([
            "--label",
            *labels
        ])
    if annotation is not None:
        cargs.extend([
            "--annot",
            execution.input_file(annotation)
        ])
    if segmentation is not None:
        cargs.extend([
            "--seg",
            execution.input_file(segmentation)
        ])
    cargs.extend([
        "--temp",
        execution.input_file(template)
    ])
    if registration is not None:
        cargs.extend([
            "--reg",
            execution.input_file(registration)
        ])
    if identity_flag:
        cargs.append("--identity")
    if fill_threshold is not None:
        cargs.extend([
            "--fillthresh",
            str(fill_threshold)
        ])
    if label_vox_vol is not None:
        cargs.extend([
            "--labvoxvol",
            str(label_vox_vol)
        ])
    if projection is not None:
        cargs.extend([
            "--proj",
            projection
        ])
    if subject is not None:
        cargs.extend([
            "--subject",
            subject
        ])
    if hemisphere is not None:
        cargs.extend([
            "--hemi",
            hemisphere
        ])
    cargs.extend([
        "--o",
        output_volume
    ])
    if hits_volume is not None:
        cargs.extend([
            "--hits",
            hits_volume
        ])
    if label_stat_volume is not None:
        cargs.extend([
            "--label-stat",
            label_stat_volume
        ])
    if stat_threshold is not None:
        cargs.extend([
            "--stat-thresh",
            str(stat_threshold)
        ])
    if offset is not None:
        cargs.extend([
            "--offset",
            str(offset)
        ])
    if defects is not None:
        cargs.extend([
            "--defects",
            defects
        ])
    if native_vox2ras_flag:
        cargs.append("--native-vox2ras")
    ret = MriLabel2volOutputs(
        root=execution.output_file("."),
        output_vol=execution.output_file(output_volume),
        hits_vol=execution.output_file(hits_volume) if (hits_volume is not None) else None,
        label_stat_vol=execution.output_file(label_stat_volume) if (label_stat_volume is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_LABEL2VOL_METADATA",
    "MriLabel2volOutputs",
    "mri_label2vol",
]
