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

import typing
import pathlib
from styxdefs import *
import dataclasses

IMREG_METADATA = Metadata(
    id="9eb7e2d86ad67ffd9b28c2a3619d573a48d1975b.boutiques",
    name="imreg",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class ImregOutputs(typing.NamedTuple):
    """
    Output object returned when calling `imreg(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    registered_images: OutputPathType | None
    """Registered images"""
    dx_file: OutputPathType | None
    """Time series dx file"""
    dy_file: OutputPathType | None
    """Time series dy file"""
    phi_file: OutputPathType | None
    """Time series phi file"""


def imreg(
    base_image: str,
    image_sequence: list[InputPathType],
    nowrite: bool = False,
    prefix: str | None = None,
    suffix: str | None = None,
    start: float | None = None,
    step: float | None = None,
    flim: bool = False,
    keepsize: bool = False,
    quiet: bool = False,
    debug: bool = False,
    dprefix: str | None = None,
    bilinear: bool = False,
    modes: str | None = None,
    mlcf: bool = False,
    wtim: InputPathType | None = None,
    dfspace: bool = False,
    cmass: bool = False,
    fine: list[float] | None = None,
    nofine: bool = False,
    runner: Runner | None = None,
) -> ImregOutputs:
    """
    Registers each 2D image in 'image_sequence' to 'base_image'.
    
    Author: AFNI Team
    
    URL: https://afni.nimh.nih.gov/pub/dist/doc/program_help/imreg.html
    
    Args:
        base_image: Base image or method to determine base image ('+AVER' or\
            '+count').
        image_sequence: Sequence of images to be registered.
        nowrite: Don't write outputs, just print progress reports.
        prefix: Prefix for output file names.
        suffix: Suffix for output file names.
        start: Start index for output file names.
        step: Step size for output file indices.
        flim: Write output in mrilib floating point format.
        keepsize: Preserve the original image size on output.
        quiet: Don't write progress report messages.
        debug: Write lots of debugging output.
        dprefix: Prefix for dx, dy, and phi files.
        bilinear: Use bilinear interpolation.
        modes: Interpolation modes during coarse, fine, and registration phases.
        mlcf: Equivalent to '-modes bilinear bicubic Fourier'.
        wtim: Weighting image file.
        dfspace: Use difiterated differential spatial method.
        cmass: Align centers of mass of the images.
        fine: Fine fit parameters: blur, dxy, dphi.
        nofine: Turn off the 'fine' fit algorithm.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ImregOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(IMREG_METADATA)
    cargs = []
    cargs.append("imreg")
    cargs.append(base_image)
    cargs.extend([execution.input_file(f) for f in image_sequence])
    if nowrite:
        cargs.append("-nowrite")
    if prefix is not None:
        cargs.extend([
            "-prefix",
            prefix
        ])
    if suffix is not None:
        cargs.extend([
            "-suffix",
            suffix
        ])
    if start is not None:
        cargs.extend([
            "-start",
            str(start)
        ])
    if step is not None:
        cargs.extend([
            "-step",
            str(step)
        ])
    if flim:
        cargs.append("-flim")
    if keepsize:
        cargs.append("-keepsize")
    if quiet:
        cargs.append("-quiet")
    if debug:
        cargs.append("-debug")
    if dprefix is not None:
        cargs.extend([
            "-dprefix",
            dprefix
        ])
    if bilinear:
        cargs.append("-bilinear")
    if modes is not None:
        cargs.extend([
            "-modes",
            modes
        ])
    if mlcf:
        cargs.append("-mlcF")
    if wtim is not None:
        cargs.extend([
            "-wtim",
            execution.input_file(wtim)
        ])
    if dfspace:
        cargs.append("-dfspace")
    if cmass:
        cargs.append("-cmass")
    if fine is not None:
        cargs.extend([
            "-fine",
            *map(str, fine)
        ])
    if nofine:
        cargs.append("-nofine")
    ret = ImregOutputs(
        root=execution.output_file("."),
        registered_images=execution.output_file(prefix + ".[INDEX]." + suffix) if (prefix is not None and suffix is not None) else None,
        dx_file=execution.output_file(dprefix + ".dx") if (dprefix is not None) else None,
        dy_file=execution.output_file(dprefix + ".dy") if (dprefix is not None) else None,
        phi_file=execution.output_file(dprefix + ".phi") if (dprefix is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "IMREG_METADATA",
    "ImregOutputs",
    "imreg",
]
