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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_SEGMENT_METADATA = Metadata(
    id="0045da93f1222aff1ebe9296139c24c805b6f653.boutiques",
    name="mri_segment",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriSegmentOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_segment(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_volume: OutputPathType
    """Segmented white matter output volume"""
    log_file: OutputPathType
    """Log file from segmentation process"""


def mri_segment(
    in_vol: InputPathType,
    out_vol: str,
    no1d_remove: float | None = None,
    slope: float | None = None,
    pslope: float | None = 1.0,
    nslope: float | None = 1.0,
    debug_voxel: list[float] | None = None,
    auto: bool = False,
    noauto: bool = False,
    log: bool = False,
    keep: bool = False,
    gray_hi: float | None = 100.0,
    wm_low: float | None = 80.0,
    wm_low_factor: float | None = None,
    wm_hi: float | None = 125.0,
    nseg: float | None = 20,
    thicken: bool = False,
    fillbg: bool = False,
    fillv: bool = False,
    blur_sigma: float | None = 0.25,
    iterations: float | None = 1,
    thin_strand_limit: float | None = 4,
    verbose: bool = False,
    threshold: float | None = 0.8,
    extract_options: InputPathType | None = None,
    wsize: float | None = 11,
    wsizemm: float | None = None,
    polvw_size: float | None = 5,
    polv_len: float | None = 3,
    datfile: InputPathType | None = None,
    segmentation: str | None = None,
    diagno: float | None = None,
    diag_write: bool = False,
    diag_verbose: bool = False,
    runner: Runner | None = None,
) -> MriSegmentOutputs:
    """
    Segments white matter from the input volume.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        in_vol: Input volume to be segmented.
        out_vol: Output volume after segmentation.
        no1d_remove: Don't run code that removes 1D strands from segmentation.
        slope: Set the curvature slope (both n and p).
        pslope: Set the curvature pslope (default=1.0).
        nslope: Set the curvature nslope (default=1.0).
        debug_voxel: Set voxel for debugging.
        auto: Automatically detect class statistics (default).
        noauto: Don't automatically detect class statistics.
        log: Log to ./segment.dat.
        keep: Keep wm edits, maintains all values of 1 and 255.
        gray_hi: Set the gray matter high limit (default=100.000).
        wm_low: Set the white matter low limit (default=80.000).
        wm_low_factor: wm_low = f*gray_mean + (1-f)*white_mean;.
        wm_hi: Set the white matter high limit (default=125.000).
        nseg: Thicken the n largest thin strands (default=20).
        thicken: Toggle thickening step (default=ON).
        fillbg: Toggle filling of the basal ganglia (default=OFF).
        fillv: Toggle filling of the ventricles (default=OFF).
        blur_sigma: Set blur sigma (default=0.25).
        iterations: Set # iterations of border classification (default=1).
        thin_strand_limit: Set limit to thin strands in mm (default=4).
        verbose: Verbose.
        threshold: Set % threshold (default=0.80).
        extract_options: Extract options from filename.
        wsize: Set wsize (default=11 voxels).
        wsizemm: Set wsize based on mm instead of voxels.
        polvw_size: Set wsize for plane of least variance (default=5).
        polv_len: Set length for plane of least variance (default=3).
        datfile: Set datfile (default is segment.dat).
        segmentation: Use segmentation to set thresholds.
        diagno: Set diagnostic number.
        diag_write: Set diagnostic write.
        diag_verbose: Set diagnostic verbose.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriSegmentOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_SEGMENT_METADATA)
    cargs = []
    cargs.append("mri_segment")
    cargs.append(execution.input_file(in_vol))
    cargs.append(out_vol)
    if no1d_remove is not None:
        cargs.extend([
            "-no1d_remove",
            str(no1d_remove)
        ])
    if slope is not None:
        cargs.extend([
            "-slope",
            str(slope)
        ])
    if pslope is not None:
        cargs.extend([
            "-pslope",
            str(pslope)
        ])
    if nslope is not None:
        cargs.extend([
            "-nslope",
            str(nslope)
        ])
    if debug_voxel is not None:
        cargs.extend([
            "-debug_voxel",
            *map(str, debug_voxel)
        ])
    if auto:
        cargs.append("-auto")
    if noauto:
        cargs.append("-noauto")
    if log:
        cargs.append("-log")
    if keep:
        cargs.append("-keep")
    if gray_hi is not None:
        cargs.extend([
            "-ghi",
            str(gray_hi)
        ])
    if wm_low is not None:
        cargs.extend([
            "-wlo",
            str(wm_low)
        ])
    if wm_low_factor is not None:
        cargs.extend([
            "-wm_low_factor",
            str(wm_low_factor)
        ])
    if wm_hi is not None:
        cargs.extend([
            "-whi",
            str(wm_hi)
        ])
    if nseg is not None:
        cargs.extend([
            "-nseg",
            str(nseg)
        ])
    if thicken:
        cargs.append("-thicken")
    if fillbg:
        cargs.append("-fillbg")
    if fillv:
        cargs.append("-fillv")
    if blur_sigma is not None:
        cargs.extend([
            "-b",
            str(blur_sigma)
        ])
    if iterations is not None:
        cargs.extend([
            "-n",
            str(iterations)
        ])
    if thin_strand_limit is not None:
        cargs.extend([
            "-t",
            str(thin_strand_limit)
        ])
    if verbose:
        cargs.append("-v")
    if threshold is not None:
        cargs.extend([
            "-p",
            str(threshold)
        ])
    if extract_options is not None:
        cargs.extend([
            "-x",
            execution.input_file(extract_options)
        ])
    if wsize is not None:
        cargs.extend([
            "-w",
            str(wsize)
        ])
    if wsizemm is not None:
        cargs.extend([
            "-wsizemm",
            str(wsizemm)
        ])
    if polvw_size is not None:
        cargs.extend([
            "-polvwsize",
            str(polvw_size)
        ])
    if polv_len is not None:
        cargs.extend([
            "-polvlen",
            str(polv_len)
        ])
    if datfile is not None:
        cargs.extend([
            "-dat",
            execution.input_file(datfile)
        ])
    if segmentation is not None:
        cargs.extend([
            "-seg",
            segmentation
        ])
    if diagno is not None:
        cargs.extend([
            "-diagno",
            str(diagno)
        ])
    if diag_write:
        cargs.append("-diag-write")
    if diag_verbose:
        cargs.append("-diag-verbose")
    ret = MriSegmentOutputs(
        root=execution.output_file("."),
        output_volume=execution.output_file(out_vol),
        log_file=execution.output_file("./segment.dat"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_SEGMENT_METADATA",
    "MriSegmentOutputs",
    "mri_segment",
]
