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

import typing
import pathlib
from styxdefs import *
import dataclasses

FIM2_METADATA = Metadata(
    id="dc4766ddbc19de164de7f967033e9406b2958bcf.boutiques",
    name="fim2",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class Fim2Outputs(typing.NamedTuple):
    """
    Output object returned when calling `fim2(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    activation_magnitudes: OutputPathType | None
    """Activation magnitudes output file"""
    correlation_image: OutputPathType | None
    """Correlation image output file"""
    contrast_to_noise_image: OutputPathType | None
    """Contrast-to-noise image output file"""
    std_deviation_image: OutputPathType | None
    """Standard deviation image output file"""
    ls_fit_coefficients: OutputPathType | None
    """Least squares fit coefficients image files"""
    subtracted_references: OutputPathType | None
    """Subtracted ortho reference time series images"""


def fim2(
    image_files: list[InputPathType],
    pcnt: float | None = None,
    pcthresh: float | None = None,
    im1: int | None = None,
    num: int | None = None,
    non: bool = False,
    coef: float | None = None,
    ort: list[InputPathType] | None = None,
    ideal: list[InputPathType] | None = None,
    polref: int | None = None,
    fimfile: str | None = None,
    corr: bool = False,
    corfile: str | None = None,
    cnrfile: str | None = None,
    sigfile: str | None = None,
    fitfile: str | None = None,
    subort: str | None = None,
    flim: bool = False,
    clean: bool = False,
    clip: bool = False,
    q: bool = False,
    dfspace: bool = False,
    regbase: str | None = None,
    runner: Runner | None = None,
) -> Fim2Outputs:
    """
    Functional Imaging Mapping Tool.
    
    Author: AFNI Developers
    
    URL: https://afni.nimh.nih.gov/
    
    Args:
        image_files: Input MRI image files.
        pcnt: Correlation coefficient threshold will be 1 - 0.01 * #.
        pcthresh: Correlation coefficient threshold will be #.
        im1: Index of image file to use as first in time series; default is 1.
        num: Number of images to actually use; default is to use all images.
        non: Turn off default normalization of the output activation image.
        coef: Scaling factor to convert the activation output from floats to\
            short ints.
        ort: Filename of a time series to which the image data will be\
            orthogonalized before correlations are computed.
        ideal: Filename of a time series to which the image data is to be\
            correlated.
        polref: Use polynomials of order 0..# as extra 'orts'; default is 0.
        fimfile: Filename to save activation magnitudes in.
        corr: Indicates to write correlation output to image file\
            'fimfile.CORR'.
        corfile: Filename to save correlation image in.
        cnrfile: Filename to save contrast-to-noise image in.
        sigfile: Filename to save standard deviation image in.
        fitfile: Image files of the least squares fit coefficients of all the\
            -ort and -polref time series.
        subort: Filename of the new timeseries of images with the orts and\
            polrefs subtracted out.
        flim: Write outputs in mrilib 'float' format.
        clean: Output images won't have the +/- 10000 values forced into their\
            corners for scaling purposes.
        clip: Set to zero regions of low intensity in output correlations, etc.
        q: Quiet operation mode.
        dfspace: Use the 'dfspace' filter to register the images spatially\
            before filtering.
        regbase: Read image in file 'fname' as the base image for registration.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Fim2Outputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(FIM2_METADATA)
    cargs = []
    cargs.append("fim2")
    cargs.extend([execution.input_file(f) for f in image_files])
    if pcnt is not None:
        cargs.extend([
            "-pcnt",
            str(pcnt)
        ])
    if pcthresh is not None:
        cargs.extend([
            "-pcthresh",
            str(pcthresh)
        ])
    if im1 is not None:
        cargs.extend([
            "-im1",
            str(im1)
        ])
    if num is not None:
        cargs.extend([
            "-num",
            str(num)
        ])
    if non:
        cargs.append("-non")
    if coef is not None:
        cargs.extend([
            "-coef",
            str(coef)
        ])
    if ort is not None:
        cargs.extend([
            "-ort",
            *[execution.input_file(f) for f in ort]
        ])
    if ideal is not None:
        cargs.extend([
            "-ideal",
            *[execution.input_file(f) for f in ideal]
        ])
    if polref is not None:
        cargs.extend([
            "-polref",
            str(polref)
        ])
    if fimfile is not None:
        cargs.extend([
            "-fimfile",
            fimfile
        ])
    if corr:
        cargs.append("-corr")
    if corfile is not None:
        cargs.extend([
            "-corfile",
            corfile
        ])
    if cnrfile is not None:
        cargs.extend([
            "-cnrfile",
            cnrfile
        ])
    if sigfile is not None:
        cargs.extend([
            "-sigfile",
            sigfile
        ])
    if fitfile is not None:
        cargs.extend([
            "-fitfile",
            fitfile
        ])
    if subort is not None:
        cargs.extend([
            "-subort",
            subort
        ])
    if flim:
        cargs.append("-flim")
    if clean:
        cargs.append("-clean")
    if clip:
        cargs.append("-clip")
    if q:
        cargs.append("-q")
    if dfspace:
        cargs.append("-dfspace")
    if regbase is not None:
        cargs.extend([
            "-regbase",
            regbase
        ])
    ret = Fim2Outputs(
        root=execution.output_file("."),
        activation_magnitudes=execution.output_file(fimfile) if (fimfile is not None) else None,
        correlation_image=execution.output_file(corfile) if (corfile is not None) else None,
        contrast_to_noise_image=execution.output_file(cnrfile) if (cnrfile is not None) else None,
        std_deviation_image=execution.output_file(sigfile) if (sigfile is not None) else None,
        ls_fit_coefficients=execution.output_file(fitfile) if (fitfile is not None) else None,
        subtracted_references=execution.output_file(subort) if (subort is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "FIM2_METADATA",
    "Fim2Outputs",
    "fim2",
]
