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

import typing
import pathlib
from styxdefs import *
import dataclasses

EPIDEWARP_FSL_METADATA = Metadata(
    id="0b6f576dc06a529efd6bb20065d0ee4307b24409.boutiques",
    name="epidewarp.fsl",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class EpidewarpFslOutputs(typing.NamedTuple):
    """
    Output object returned when calling `epidewarp_fsl(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    vsm_output: OutputPathType
    """Voxel Shift Map output"""
    exfdw_output: OutputPathType | None
    """Dewarped example func volume"""
    epidw_output: OutputPathType | None
    """Dewarped EPI volume"""
    vsmmag_output: OutputPathType | None
    """Voxel shift map in mag space output"""


def epidewarp_fsl(
    vsm: str,
    mag: InputPathType | None = None,
    dph: InputPathType | None = None,
    ph: InputPathType | None = None,
    complex_: list[float] | None = None,
    exf: InputPathType | None = None,
    epi: InputPathType | None = None,
    tediff: float | None = None,
    esp: float | None = None,
    perev: bool = False,
    sigma: float | None = None,
    vsm_fwhm: float | None = None,
    vsmmag: str | None = None,
    exfdw: str | None = None,
    epidw: str | None = None,
    nomagexfreg: bool = False,
    head: bool = False,
    tmpdir: str | None = None,
    log: str | None = None,
    nocleanup: bool = False,
    cleanup: bool = False,
    debug: bool = False,
    runner: Runner | None = None,
) -> EpidewarpFslOutputs:
    """
    Front end for FSL's PRELUDE and FUGUE programs to correct B0 distortion in EPI
    scans.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        vsm: Voxel shift map (required).
        mag: B0 magnitude volume.
        dph: B0 phase difference volume.
        ph: B0 phase volume.
        complex_: B0 map in complex values: real1 imag1 real2 imag2.
        exf: Example func volume.
        epi: EPI volume to unwarp.
        tediff: Difference in B0 field map TEs.
        esp: EPI echo spacing.
        perev: Assume reversed phase encode direction.
        sigma: 2D spatial gaussian smoothing stddev (default 2mm).
        vsm_fwhm: Allows VSM to be extended outside of the mask.
        vsmmag: Voxel shift map in mag space.
        exfdw: Dewarped example func volume.
        epidw: Dewarped EPI volume.
        nomagexfreg: Assume mag and exf are in register.
        head: Mask to head instead of brain.
        tmpdir: Save intermediate results here.
        log: Use logfile instead of default.
        nocleanup: Do not delete tmpdir.
        cleanup: Force deletion of tmpdir.
        debug: Prints copious amounts to the screen.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `EpidewarpFslOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(EPIDEWARP_FSL_METADATA)
    cargs = []
    cargs.append("epidewarp.fsl")
    if mag is not None:
        cargs.extend([
            "--mag",
            execution.input_file(mag)
        ])
    if dph is not None:
        cargs.extend([
            "--dph",
            execution.input_file(dph)
        ])
    if ph is not None:
        cargs.extend([
            "--ph",
            execution.input_file(ph)
        ])
    if complex_ is not None:
        cargs.extend([
            "--complex",
            *map(str, complex_)
        ])
    if exf is not None:
        cargs.extend([
            "--exf",
            execution.input_file(exf)
        ])
    if epi is not None:
        cargs.extend([
            "--epi",
            execution.input_file(epi)
        ])
    if tediff is not None:
        cargs.extend([
            "--tediff",
            str(tediff)
        ])
    if esp is not None:
        cargs.extend([
            "--esp",
            str(esp)
        ])
    if perev:
        cargs.append("--perev")
    if sigma is not None:
        cargs.extend([
            "--sigma",
            str(sigma)
        ])
    if vsm_fwhm is not None:
        cargs.extend([
            "--vsm-fwhm",
            str(vsm_fwhm)
        ])
    cargs.extend([
        "--vsm",
        vsm
    ])
    if vsmmag is not None:
        cargs.extend([
            "--vsmmag",
            vsmmag
        ])
    if exfdw is not None:
        cargs.extend([
            "--exfdw",
            exfdw
        ])
    if epidw is not None:
        cargs.extend([
            "--epidw",
            epidw
        ])
    if nomagexfreg:
        cargs.append("--nomagexfreg")
    if head:
        cargs.append("--head")
    if tmpdir is not None:
        cargs.extend([
            "--tmpdir",
            tmpdir
        ])
    if log is not None:
        cargs.extend([
            "--log",
            log
        ])
    if nocleanup:
        cargs.append("--nocleanup")
    if cleanup:
        cargs.append("--cleanup")
    if debug:
        cargs.append("--debug")
    ret = EpidewarpFslOutputs(
        root=execution.output_file("."),
        vsm_output=execution.output_file(vsm + ".nii.gz"),
        exfdw_output=execution.output_file(exfdw + ".nii.gz") if (exfdw is not None) else None,
        epidw_output=execution.output_file(epidw + ".nii.gz") if (epidw is not None) else None,
        vsmmag_output=execution.output_file(vsmmag + ".nii.gz") if (vsmmag is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "EPIDEWARP_FSL_METADATA",
    "EpidewarpFslOutputs",
    "epidewarp_fsl",
]
