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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_WATERSHED_METADATA = Metadata(
    id="1390c3e2e9ad7d6fa430f8cfd5c3863c2de5ce50.boutiques",
    name="mri_watershed",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriWatershedOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_watershed(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_brain_vol: OutputPathType
    """Skull stripped brain volume"""
    output_brain_surf: OutputPathType | None
    """Saved brain surface when specified"""


def mri_watershed(
    input_volume: InputPathType,
    output_volume: str,
    weight: float | None = None,
    no_wta_flag: bool = False,
    proba_merging: float | None = None,
    preflooding_height: float | None = None,
    no_seedpt_flag: bool = False,
    no_ta_flag: bool = False,
    copy_flag: bool = False,
    atlas_flag: bool = False,
    surf_name: str | None = None,
    usesurf_ras_flag: bool = False,
    no_t1_analysis_flag: bool = False,
    shrink_surface_flag: bool = False,
    expand_surface_flag: bool = False,
    use_watershed_flag: bool = False,
    t1_volume: InputPathType | None = None,
    wat_temp_flag: bool = False,
    first_temp_flag: bool = False,
    surf_debug_flag: bool = False,
    brain_surf_name: str | None = None,
    shrink_brain_surf: str | None = None,
    seed_point: list[float] | None = None,
    center_brain: list[float] | None = None,
    brain_radius: float | None = None,
    watershed_threshold: float | None = None,
    no_watershed_analysis_flag: bool = False,
    label_flag: bool = False,
    manual_params: list[float] | None = None,
    xthresh: float | None = None,
    mask_flag: bool = False,
    runner: Runner | None = None,
) -> MriWatershedOutputs:
    """
    A tool for stripping skull and other non-brain tissues to produce brain volume
    from T1 volume.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_volume: Input volume (e.g., T1 volume).
        output_volume: Output volume (e.g., skull stripped brain volume).
        weight: Preweight the input image using atlas information.
        no_wta_flag: Don't use the preweighting for the template deformation.
        proba_merging: Use the basins merging using atlas information.
        preflooding_height: Pre-size the preflooding height (in percent).
        no_seedpt_flag: Don't use seedpoints using atlas information.
        no_ta_flag: Don't use template deformation using atlas information.
        copy_flag: Just copy input to output, ignore other options.
        atlas_flag: Use the atlas information to correct the segmentation.
        surf_name: Save the BEM surfaces; use consistent coordinates with\
            tkmedit.
        usesurf_ras_flag: Use the surface RAS coordinates for surfaces.
        no_t1_analysis_flag: Don't do T1 analysis, useful when running out of\
            memory.
        shrink_surface_flag: Shrink the surface.
        expand_surface_flag: Expand the surface.
        use_watershed_flag: Use only the watershed algorithm.
        t1_volume: Specify T1 input volume.
        wat_temp_flag: Use watershed algorithm and first template smoothing.
        first_temp_flag: Use only the first template smoothing + local matching.
        surf_debug_flag: Visualize the surfaces onto the output volume.
        brain_surf_name: Save the brain surface.
        shrink_brain_surf: Save the brain surface shrank inward by a specified\
            mm.
        seed_point: Add a seed point as a 3D coordinate.
        center_brain: Specify the center of the brain (voxel coordinates).
        brain_radius: Specify the radius of the brain (voxel units).
        watershed_threshold: Change the threshold in the watershed process.
        no_watershed_analysis_flag: Don't use the watershed analysis process.
        label_flag: Labelize the output volume into scalp, skull, csf, gray,\
            and white matter.
        manual_params: Change parameters csf_max, transition intensity, and\
            GM_intensity.
        xthresh: Remove voxels whose intensity exceeds the specified threshold.
        mask_flag: Mask a volume with the brain mask.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriWatershedOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_WATERSHED_METADATA)
    cargs = []
    cargs.append("mri_watershed")
    cargs.append(execution.input_file(input_volume))
    cargs.append(output_volume)
    if weight is not None:
        cargs.extend([
            "-w",
            str(weight)
        ])
    if no_wta_flag:
        cargs.append("-no_wta")
    if proba_merging is not None:
        cargs.extend([
            "-b",
            str(proba_merging)
        ])
    if preflooding_height is not None:
        cargs.extend([
            "-h",
            str(preflooding_height)
        ])
    if no_seedpt_flag:
        cargs.append("-no_seedpt")
    if no_ta_flag:
        cargs.append("-no-ta")
    if copy_flag:
        cargs.append("-copy")
    if atlas_flag:
        cargs.append("-atlas")
    if surf_name is not None:
        cargs.extend([
            "-surf",
            surf_name
        ])
    if usesurf_ras_flag:
        cargs.append("-useSRAS")
    if no_t1_analysis_flag:
        cargs.append("-noT1")
    if shrink_surface_flag:
        cargs.append("-less")
    if expand_surface_flag:
        cargs.append("-more")
    if use_watershed_flag:
        cargs.append("-wat")
    if t1_volume is not None:
        cargs.extend([
            "-T1",
            execution.input_file(t1_volume)
        ])
    if wat_temp_flag:
        cargs.append("-wat+temp")
    if first_temp_flag:
        cargs.append("-first_temp")
    if surf_debug_flag:
        cargs.append("-surf_debug")
    if brain_surf_name is not None:
        cargs.extend([
            "-brainsurf",
            brain_surf_name
        ])
    if shrink_brain_surf is not None:
        cargs.extend([
            "-shk_br_surf",
            shrink_brain_surf
        ])
    if seed_point is not None:
        cargs.extend([
            "-s",
            *map(str, seed_point)
        ])
    if center_brain is not None:
        cargs.extend([
            "-c",
            *map(str, center_brain)
        ])
    if brain_radius is not None:
        cargs.extend([
            "-r",
            str(brain_radius)
        ])
    if watershed_threshold is not None:
        cargs.extend([
            "-t",
            str(watershed_threshold)
        ])
    if no_watershed_analysis_flag:
        cargs.append("-n")
    if label_flag:
        cargs.append("-LABEL")
    if manual_params is not None:
        cargs.extend([
            "-man",
            *map(str, manual_params)
        ])
    if xthresh is not None:
        cargs.extend([
            "-xthresh",
            str(xthresh)
        ])
    if mask_flag:
        cargs.append("-mask")
    ret = MriWatershedOutputs(
        root=execution.output_file("."),
        output_brain_vol=execution.output_file(output_volume),
        output_brain_surf=execution.output_file(brain_surf_name) if (brain_surf_name is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_WATERSHED_METADATA",
    "MriWatershedOutputs",
    "mri_watershed",
]
