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

import typing
import pathlib
from styxdefs import *
import dataclasses

PRELUDE_METADATA = Metadata(
    id="5adffe55db73f990a6bff1ef9b7c656a99d9928b.boutiques",
    name="prelude",
    package="fsl",
    container_image_tag="brainlife/fsl:6.0.4-patched2",
)


class PreludeOutputs(typing.NamedTuple):
    """
    Output object returned when calling `prelude(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    unwrapped_phase_output: OutputPathType
    """Unwrapped phase output file"""
    saved_mask_volume: OutputPathType | None
    """Saved mask volume file"""
    saved_raw_phase_output: OutputPathType | None
    """Saved raw phase output file"""
    saved_area_labels_output: OutputPathType | None
    """Saved area labels output file"""


def prelude(
    output_unwrap: InputPathType,
    output_unwrap_alias: InputPathType,
    complex_phase: InputPathType | None = None,
    complex_phase_alias: InputPathType | None = None,
    absolute_volume: InputPathType | None = None,
    absolute_volume_alias: InputPathType | None = None,
    phase_volume: InputPathType | None = None,
    phase_volume_alias: InputPathType | None = None,
    num_phase_split: float | None = None,
    label_slices: bool = False,
    slice_processing: bool = False,
    slice_processing_alias: bool = False,
    force_3d: bool = False,
    force_3d_alias: bool = False,
    threshold: float | None = None,
    threshold_alias: float | None = None,
    mask_volume: InputPathType | None = None,
    mask_volume_alias: InputPathType | None = None,
    start_image: float | None = None,
    end_image: float | None = None,
    save_mask: InputPathType | None = None,
    save_raw_phase: InputPathType | None = None,
    save_raw_phase_alias: InputPathType | None = None,
    save_labels: InputPathType | None = None,
    save_labels_alias: InputPathType | None = None,
    remove_ramps: bool = False,
    verbose: bool = False,
    verbose_alias: bool = False,
    help_: bool = False,
    help_alias: bool = False,
    runner: Runner | None = None,
) -> PreludeOutputs:
    """
    Phase Region Expanding Labeller for Unwrapping Discrete Estimates.
    
    Author: FMRIB Analysis Group, University of Oxford
    
    URL: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki
    
    Args:
        output_unwrap: Filename for saving the unwrapped phase output.
        output_unwrap_alias: Filename for saving the unwrapped phase output.
        complex_phase: Filename of complex phase input volume.
        complex_phase_alias: Filename of complex phase input volume.
        absolute_volume: Filename of absolute input volume.
        absolute_volume_alias: Filename of absolute input volume.
        phase_volume: Filename of raw phase input volume.
        phase_volume_alias: Filename of raw phase input volume.
        num_phase_split: Number of phase partitions to use.
        label_slices: Does label processing in 2D (slice at a time).
        slice_processing: Does all processing in 2D (slice at a time).
        slice_processing_alias: Does all processing in 2D (slice at a time).
        force_3d: Forces all processing to be full 3D.
        force_3d_alias: Forces all processing to be full 3D.
        threshold: Intensity threshold for masking.
        threshold_alias: Intensity threshold for masking.
        mask_volume: Filename of mask input volume.
        mask_volume_alias: Filename of mask input volume.
        start_image: First image number to process (default 0).
        end_image: Final image number to process (default Inf).
        save_mask: Filename for saving the mask volume.
        save_raw_phase: Filename for saving the raw phase output.
        save_raw_phase_alias: Filename for saving the raw phase output.
        save_labels: Filename for saving the area labels output.
        save_labels_alias: Filename for saving the area labels output.
        remove_ramps: Remove phase ramps during unwrapping.
        verbose: Switch on diagnostic messages.
        verbose_alias: Switch on diagnostic messages.
        help_: Display help message.
        help_alias: Display help message.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `PreludeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(PRELUDE_METADATA)
    cargs = []
    cargs.append("prelude")
    cargs.extend([
        "-o",
        execution.input_file(output_unwrap)
    ])
    cargs.extend([
        "-u",
        execution.input_file(output_unwrap_alias)
    ])
    if complex_phase is not None:
        cargs.extend([
            "-c",
            execution.input_file(complex_phase)
        ])
    if complex_phase_alias is not None:
        cargs.extend([
            "--complex",
            execution.input_file(complex_phase_alias)
        ])
    if absolute_volume is not None:
        cargs.extend([
            "-a",
            execution.input_file(absolute_volume)
        ])
    if absolute_volume_alias is not None:
        cargs.extend([
            "--abs",
            execution.input_file(absolute_volume_alias)
        ])
    if phase_volume is not None:
        cargs.extend([
            "-p",
            execution.input_file(phase_volume)
        ])
    if phase_volume_alias is not None:
        cargs.extend([
            "--phase",
            execution.input_file(phase_volume_alias)
        ])
    if num_phase_split is not None:
        cargs.extend([
            "-n",
            str(num_phase_split)
        ])
    if label_slices:
        cargs.append("--labelslices")
    if slice_processing:
        cargs.append("-s")
    if slice_processing_alias:
        cargs.append("--slices")
    if force_3d:
        cargs.append("-f")
    if force_3d_alias:
        cargs.append("--force3D")
    if threshold is not None:
        cargs.extend([
            "-t",
            str(threshold)
        ])
    if threshold_alias is not None:
        cargs.extend([
            "--thresh",
            str(threshold_alias)
        ])
    if mask_volume is not None:
        cargs.extend([
            "-m",
            execution.input_file(mask_volume)
        ])
    if mask_volume_alias is not None:
        cargs.extend([
            "--mask",
            execution.input_file(mask_volume_alias)
        ])
    if start_image is not None:
        cargs.extend([
            "--start",
            str(start_image)
        ])
    if end_image is not None:
        cargs.extend([
            "--end",
            str(end_image)
        ])
    if save_mask is not None:
        cargs.extend([
            "--savemask",
            execution.input_file(save_mask)
        ])
    if save_raw_phase is not None:
        cargs.extend([
            "-r",
            execution.input_file(save_raw_phase)
        ])
    if save_raw_phase_alias is not None:
        cargs.extend([
            "--rawphase",
            execution.input_file(save_raw_phase_alias)
        ])
    if save_labels is not None:
        cargs.extend([
            "-l",
            execution.input_file(save_labels)
        ])
    if save_labels_alias is not None:
        cargs.extend([
            "--labels",
            execution.input_file(save_labels_alias)
        ])
    if remove_ramps:
        cargs.append("--removeramps")
    if verbose:
        cargs.append("-v")
    if verbose_alias:
        cargs.append("--verbose")
    if help_:
        cargs.append("-h")
    if help_alias:
        cargs.append("--help")
    ret = PreludeOutputs(
        root=execution.output_file("."),
        unwrapped_phase_output=execution.output_file(pathlib.Path(output_unwrap).name + ".nii.gz"),
        saved_mask_volume=execution.output_file(pathlib.Path(save_mask).name + ".nii.gz") if (save_mask is not None) else None,
        saved_raw_phase_output=execution.output_file(pathlib.Path(save_raw_phase).name + ".nii.gz") if (save_raw_phase is not None) else None,
        saved_area_labels_output=execution.output_file(pathlib.Path(save_labels).name + ".nii.gz") if (save_labels is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "PRELUDE_METADATA",
    "PreludeOutputs",
    "prelude",
]
