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

import typing
import pathlib
from styxdefs import *
import dataclasses

FSL_PREPARE_FIELDMAP_METADATA = Metadata(
    id="6b22511c0f991a159ff6fb3ceff68a57bc1d3fe6.boutiques",
    name="fsl_prepare_fieldmap",
    package="fsl",
    container_image_tag="mcin/fsl:6.0.5",
)


class FslPrepareFieldmapOutputs(typing.NamedTuple):
    """
    Output object returned when calling `fsl_prepare_fieldmap(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_fieldmap: OutputPathType
    """The output fieldmap in rad/s format"""


def fsl_prepare_fieldmap(
    scanner: str,
    phase_image: InputPathType,
    magnitude_image: InputPathType,
    out_image: str,
    delta_te: float,
    nocheck_flag: bool = False,
    runner: Runner | None = None,
) -> FslPrepareFieldmapOutputs:
    """
    Prepares a fieldmap suitable for FEAT from SIEMENS data and saves output in
    rad/s format.
    
    Author: Oxford Centre for Functional MRI of the Brain (FMRIB)
    
    URL: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/PrepareFieldmap
    
    Args:
        scanner: Scanner type (must be SIEMENS).
        phase_image: Phase image file.
        magnitude_image: Magnitude image file (should be Brain Extracted).
        out_image: Output fieldmap image file.
        delta_te: Echo time difference of the fieldmap sequence in milliseconds.
        nocheck_flag: Suppress automatic sanity checking of image\
            size/range/dimensions.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FslPrepareFieldmapOutputs`).
    """
    if not (0 <= delta_te): 
        raise ValueError(f"'delta_te' must be greater than 0 <= x but was {delta_te}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(FSL_PREPARE_FIELDMAP_METADATA)
    cargs = []
    cargs.append("fsl_prepare_fieldmap")
    cargs.append(scanner)
    cargs.append(execution.input_file(phase_image))
    cargs.append(execution.input_file(magnitude_image))
    cargs.append(out_image)
    cargs.append(str(delta_te))
    if nocheck_flag:
        cargs.append("--nocheck")
    ret = FslPrepareFieldmapOutputs(
        root=execution.output_file("."),
        output_fieldmap=execution.output_file(out_image + ".nii.gz"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "FSL_PREPARE_FIELDMAP_METADATA",
    "FslPrepareFieldmapOutputs",
    "fsl_prepare_fieldmap",
]
