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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_NL_ALIGN_METADATA = Metadata(
    id="cd2a19b23e2fec00175500358afe679cc9ee7fc7.boutiques",
    name="mri_nl_align",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriNlAlignOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_nl_align(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    warp_output: OutputPathType
    """Resulting warp output file after alignment"""


def mri_nl_align(
    source: InputPathType,
    target: InputPathType,
    warp: str,
    debug_voxel: list[float] | None = None,
    debug_node: list[float] | None = None,
    no_neg: float | None = None,
    renormalize: float | None = None,
    aseg_flag: bool = False,
    diag_volume: str | None = None,
    optimal_flag: bool = False,
    momentum_flag: bool = False,
    fixed_flag: bool = False,
    distance: float | None = None,
    dtrans: float | None = None,
    match_peak_flag: bool = False,
    erode: float | None = None,
    match_mean: float | None = None,
    intensity: float | None = None,
    noregrid_flag: bool = False,
    regrid_flag: bool = False,
    view: list[float] | None = None,
    levels: float | None = None,
    area_smoothness: float | None = None,
    area: float | None = None,
    tolerance: float | None = None,
    sigma: float | None = None,
    min_sigma: float | None = None,
    ribbon: InputPathType | None = None,
    rthresh: float | None = None,
    scale: float | None = None,
    dt: float | None = None,
    passes: float | None = None,
    skip: float | None = None,
    apply: float | None = None,
    distance_log: float | None = None,
    momentum: float | None = None,
    iterations: float | None = None,
    smoothness: float | None = None,
    transform: InputPathType | None = None,
    inverse_transform: InputPathType | None = None,
    binary: float | None = None,
    jacobian: float | None = None,
    disable_zero_locations: float | None = None,
    smooth_averages: float | None = None,
    exp_k: float | None = None,
    diagnostics: float | None = None,
    runner: Runner | None = None,
) -> MriNlAlignOutputs:
    """
    mri_nl_align aligns two images using nonlinear registration.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        source: Input source image file.
        target: Input target image file.
        warp: Output warp file.
        debug_voxel: Debug voxel coordinates (Gx, Gy, Gz).
        debug_node: Debug node coordinates (Gx, Gy, Gz).
        no_neg: Control allowing temporary folds during numerical minimization.
        renormalize: Control for renormalizing intensities.
        aseg_flag: Treat inputs as segmentations.
        diag_volume: Write d2 diagnostics for input volume.
        optimal_flag: Use line search optimization.
        momentum_flag: Use fixed time-step integration.
        fixed_flag: Use fixed time-step integration.
        distance: Expand border by specified mm every outer cycle.
        dtrans: Set distance transform coefficient.
        match_peak_flag: Match peak of intensity ratio histogram.
        erode: Erode source and target image specified times before morphing.
        match_mean: Control for matching peak of intensity ratio histogram.
        intensity: Set l_log_likelihood to specified value.
        noregrid_flag: Disable regridding.
        regrid_flag: Enable regridding.
        view: View voxel coordinates (Gx, Gy, Gz).
        levels: Set levels to specified value.
        area_smoothness: Set l_area_smoothness to specified value.
        area: Set l_area to specified value.
        tolerance: Set tolerance to specified value.
        sigma: Set sigma to specified value.
        min_sigma: Set minimum sigma value.
        ribbon: Read ribbon from specified file and insert into aseg.
        rthresh: Set compression ratio threshold to specified value.
        scale: Scale input values by specified factor.
        dt: Set dt to specified value.
        passes: Integrate in specified number of passes.
        skip: Skip specified number of voxels in source data.
        apply: Control for applying transform after registration.
        distance_log: Set l_distance to specified value.
        momentum: Set momentum to specified value.
        iterations: Set number of iterations to specified value.
        smoothness: Set l_smoothness to specified value.
        transform: Read the forward transform from specified file.
        inverse_transform: Read the inverse transform from specified file.
        binary: Set l_binary to specified value.
        jacobian: Set l_jacobian to specified value.
        disable_zero_locations: Control for disabling zero image locations.
        smooth_averages: Smooth gradient with specified number of averages.
        exp_k: Set exp_k to specified value.
        diagnostics: Write diagnostics at each specified iteration.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriNlAlignOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_NL_ALIGN_METADATA)
    cargs = []
    cargs.append("mri_nl_align")
    cargs.append(execution.input_file(source))
    cargs.append(execution.input_file(target))
    cargs.append(warp)
    if debug_voxel is not None:
        cargs.extend([
            "-debug_voxel",
            *map(str, debug_voxel)
        ])
    if debug_node is not None:
        cargs.extend([
            "-debug_node",
            *map(str, debug_node)
        ])
    if no_neg is not None:
        cargs.extend([
            "-noneg",
            str(no_neg)
        ])
    if renormalize is not None:
        cargs.extend([
            "-renormalize",
            str(renormalize)
        ])
    if aseg_flag:
        cargs.append("-aseg")
    if diag_volume is not None:
        cargs.extend([
            "-diag2",
            diag_volume
        ])
    if optimal_flag:
        cargs.append("-OPTIMAL")
    if momentum_flag:
        cargs.append("-MOMENTUM")
    if fixed_flag:
        cargs.append("-FIXED")
    if distance is not None:
        cargs.extend([
            "-distance",
            str(distance)
        ])
    if dtrans is not None:
        cargs.extend([
            "-dtrans",
            str(dtrans)
        ])
    if match_peak_flag:
        cargs.append("-match_peak")
    if erode is not None:
        cargs.extend([
            "-erode",
            str(erode)
        ])
    if match_mean is not None:
        cargs.extend([
            "-match_mean",
            str(match_mean)
        ])
    if intensity is not None:
        cargs.extend([
            "-intensity",
            str(intensity)
        ])
    if noregrid_flag:
        cargs.append("-noregrid")
    if regrid_flag:
        cargs.append("-regrid")
    if view is not None:
        cargs.extend([
            "-view",
            *map(str, view)
        ])
    if levels is not None:
        cargs.extend([
            "-levels",
            str(levels)
        ])
    if area_smoothness is not None:
        cargs.extend([
            "-areasmoothness",
            str(area_smoothness)
        ])
    if area is not None:
        cargs.extend([
            "-area",
            str(area)
        ])
    if tolerance is not None:
        cargs.extend([
            "-tol",
            str(tolerance)
        ])
    if sigma is not None:
        cargs.extend([
            "-sigma",
            str(sigma)
        ])
    if min_sigma is not None:
        cargs.extend([
            "-min_sigma",
            str(min_sigma)
        ])
    if ribbon is not None:
        cargs.extend([
            "-ribbon",
            execution.input_file(ribbon)
        ])
    if rthresh is not None:
        cargs.extend([
            "-rthresh",
            str(rthresh)
        ])
    if scale is not None:
        cargs.extend([
            "-scale",
            str(scale)
        ])
    if dt is not None:
        cargs.extend([
            "-dt",
            str(dt)
        ])
    if passes is not None:
        cargs.extend([
            "-passes",
            str(passes)
        ])
    if skip is not None:
        cargs.extend([
            "-skip",
            str(skip)
        ])
    if apply is not None:
        cargs.extend([
            "-apply",
            str(apply)
        ])
    if distance_log is not None:
        cargs.extend([
            "-D",
            str(distance_log)
        ])
    if momentum is not None:
        cargs.extend([
            "-M",
            str(momentum)
        ])
    if iterations is not None:
        cargs.extend([
            "-N",
            str(iterations)
        ])
    if smoothness is not None:
        cargs.extend([
            "-s",
            str(smoothness)
        ])
    if transform is not None:
        cargs.extend([
            "-T",
            execution.input_file(transform)
        ])
    if inverse_transform is not None:
        cargs.extend([
            "-I",
            execution.input_file(inverse_transform)
        ])
    if binary is not None:
        cargs.extend([
            "-B",
            str(binary)
        ])
    if jacobian is not None:
        cargs.extend([
            "-J",
            str(jacobian)
        ])
    if disable_zero_locations is not None:
        cargs.extend([
            "-Z",
            str(disable_zero_locations)
        ])
    if smooth_averages is not None:
        cargs.extend([
            "-a",
            str(smooth_averages)
        ])
    if exp_k is not None:
        cargs.extend([
            "-K",
            str(exp_k)
        ])
    if diagnostics is not None:
        cargs.extend([
            "-W",
            str(diagnostics)
        ])
    ret = MriNlAlignOutputs(
        root=execution.output_file("."),
        warp_output=execution.output_file(warp),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_NL_ALIGN_METADATA",
    "MriNlAlignOutputs",
    "mri_nl_align",
]
