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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_MS_FITPARMS_METADATA = Metadata(
    id="b0347aaf3a59e1d2a9709a64ffe1e9cfa1594acd.boutiques",
    name="mri_ms_fitparms",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriMsFitparmsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_ms_fitparms(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    t1_map: OutputPathType
    """Compressed T1 map"""
    pd_map: OutputPathType
    """Compressed Proton Density map"""
    vol0_synthetic: OutputPathType
    """Compressed Synthetic volume for input vol_1, in motion corrected space"""
    vol0_affine: OutputPathType
    """Motion correction affine information for vol_1"""
    vol1_synthetic: OutputPathType
    """Compressed Synthetic volume for input vol_2, in motion corrected space"""
    vol1_affine: OutputPathType
    """Motion correction affine information for vol_2"""


def mri_ms_fitparms(
    volumes: list[InputPathType],
    output_dir: str,
    afi_flag: bool = False,
    ait_flag: bool = False,
    at: str | None = None,
    conform_flag: bool = False,
    correct_flag: bool = False,
    cubic_flag: bool = False,
    debug_slice_flag: bool = False,
    debug_voxel_flag: bool = False,
    dt: str | None = None,
    fa: str | None = None,
    fa_scale: float | None = None,
    faf: str | None = None,
    fsmooth: float | None = None,
    invert_flag: bool = False,
    momentum: str | None = None,
    max_t2: str | None = None,
    n_iter: float | None = None,
    nearest_flag: bool = False,
    nocompress_flag: bool = False,
    nosynth_flag: bool = False,
    residuals: str | None = None,
    smooth_sigma: float | None = None,
    scale_factor: float | None = None,
    sinc_flag: bool = False,
    transform_flag: bool = False,
    echo_time: float | None = None,
    repetition_time: float | None = None,
    trilinear_flag: bool = False,
    tukey_flag: bool = False,
    help_flag: bool = False,
    use_brain_mask_flag: bool = False,
    write_intermediate: float | None = None,
    extract_subimage: list[float] | None = None,
    window_flag: bool = False,
    runner: Runner | None = None,
) -> MriMsFitparmsOutputs:
    """
    Tool for estimating T1 and PD values from FLASH images and applying
    transformations.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        volumes: List of 3D FLASH images with different flip angles.
        output_dir: Output directory.
        afi_flag: Designate flip angle map to use with nominal value 60 degrees.
        ait_flag: Apply inverse of transform.
        at: Set acquisition time.
        conform_flag: Interpolate volume to be isotropic 1mm^3.
        correct_flag: Correct proton density map (PD) by T2* estimates.
        cubic_flag: Use cubic interpolation (NOT WORKING!).
        debug_slice_flag: Debug slice processing ???.
        debug_voxel_flag: Debug voxel processing ???.
        dt: Set time step dt ???.
        fa: Set flip angle.
        fa_scale: Set value to scale all flip angles by.
        faf: Designate flip angle map to use with specified control points.
        fsmooth: Smooth flip angle map for X iterations of soap bubble\
            smoothing.
        invert_flag: Invert volumes.
        momentum: Set momentum.
        max_t2: Set max T2*.
        n_iter: Perform estimation/motion correction X times.
        nearest_flag: Use nearest-neighbor interpolation.
        nocompress_flag: Do not compress output volumes (save as .mgh).
        nosynth_flag: Disable volume synthesis.
        residuals: Write out residuals to designated location.
        smooth_sigma: Smooth faf field with sigma=X.
        scale_factor: Scale volumes by X after reading.
        sinc_flag: Use sinc interpolation (default window width is 6).
        transform_flag: Apply transform to output volumes.
        echo_time: Set echo time (TE) in ms.
        repetition_time: Set repetition time (TR) in ms.
        trilinear_flag: Use trilinear interpolation.
        tukey_flag: Use Tukey bi-weight of residuals.
        help_flag: Display help text.
        use_brain_mask_flag: Compute a brain mask from the PD map and use it\
            for registration.
        write_intermediate: Write out intermediate results every X iterations.
        extract_subimage: Extract a subimage for each input image, specified by\
            x0 y0 z0 dx dy dz.
        window_flag: Not implemented.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriMsFitparmsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_MS_FITPARMS_METADATA)
    cargs = []
    cargs.append("mri_ms_fitparms")
    cargs.extend([execution.input_file(f) for f in volumes])
    cargs.append(output_dir)
    if afi_flag:
        cargs.append("-afi")
    if ait_flag:
        cargs.append("-ait")
    if at is not None:
        cargs.extend([
            "-at",
            at
        ])
    if conform_flag:
        cargs.append("-conform")
    if correct_flag:
        cargs.append("-correct")
    if cubic_flag:
        cargs.append("-cubic")
    if debug_slice_flag:
        cargs.append("-debug_slice")
    if debug_voxel_flag:
        cargs.append("-debug_voxel")
    if dt is not None:
        cargs.extend([
            "-dt",
            dt
        ])
    if fa is not None:
        cargs.extend([
            "-fa",
            fa
        ])
    if fa_scale is not None:
        cargs.extend([
            "-fa_scale",
            str(fa_scale)
        ])
    if faf is not None:
        cargs.extend([
            "-faf",
            faf
        ])
    if fsmooth is not None:
        cargs.extend([
            "-fsmooth",
            str(fsmooth)
        ])
    if invert_flag:
        cargs.append("-i")
    if momentum is not None:
        cargs.extend([
            "-m",
            momentum
        ])
    if max_t2 is not None:
        cargs.extend([
            "-max",
            max_t2
        ])
    if n_iter is not None:
        cargs.extend([
            "-n",
            str(n_iter)
        ])
    if nearest_flag:
        cargs.append("-nearest")
    if nocompress_flag:
        cargs.append("-nocompress")
    if nosynth_flag:
        cargs.append("-nosynth")
    if residuals is not None:
        cargs.extend([
            "-r",
            residuals
        ])
    if smooth_sigma is not None:
        cargs.extend([
            "-s",
            str(smooth_sigma)
        ])
    if scale_factor is not None:
        cargs.extend([
            "-scale",
            str(scale_factor)
        ])
    if sinc_flag:
        cargs.append("-sinc")
    if transform_flag:
        cargs.append("-t")
    if echo_time is not None:
        cargs.extend([
            "-te",
            str(echo_time)
        ])
    if repetition_time is not None:
        cargs.extend([
            "-tr",
            str(repetition_time)
        ])
    if trilinear_flag:
        cargs.append("-trilinear")
    if tukey_flag:
        cargs.append("-tukey")
    if help_flag:
        cargs.append("-u")
    if use_brain_mask_flag:
        cargs.append("-use_brain_mask")
    if write_intermediate is not None:
        cargs.extend([
            "-w",
            str(write_intermediate)
        ])
    if extract_subimage is not None:
        cargs.extend([
            "-extract",
            *map(str, extract_subimage)
        ])
    if window_flag:
        cargs.append("-window")
    ret = MriMsFitparmsOutputs(
        root=execution.output_file("."),
        t1_map=execution.output_file("T1.mgz"),
        pd_map=execution.output_file("PD.mgz"),
        vol0_synthetic=execution.output_file("vol0.mgz"),
        vol0_affine=execution.output_file("vol0.lta"),
        vol1_synthetic=execution.output_file("vol1.mgz"),
        vol1_affine=execution.output_file("vol1.lta"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_MS_FITPARMS_METADATA",
    "MriMsFitparmsOutputs",
    "mri_ms_fitparms",
]
