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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_1D_NLFIT_METADATA = Metadata(
    id="2b9be7d506110a346f2427566552f2ef8767ba95.boutiques",
    name="1dNLfit",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V1dNlfitOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_1d_nlfit(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    fit_results: OutputPathType
    """Results (fitted time series models) are written to stdout. Should be
    saved by '>' redirection."""


def v_1d_nlfit(
    expression: str,
    independent_variable: str,
    parameters: list[str],
    dependent_data: InputPathType,
    method: int | None = None,
    runner: Runner | None = None,
) -> V1dNlfitOutputs:
    """
    Program to fit a model to a vector of data. The model is given by a symbolic
    expression, with parameters to be estimated.
    
    Author: AFNI Team
    
    URL: https://afni.nimh.nih.gov/pub/dist/doc/program_help/1dNLfit.html
    
    Args:
        expression: The expression for the fit. It must contain one symbol from\
            'a' to 'z' which is marked as the independent variable by option\
            '-indvar', and at least one more symbol which is a parameter to be\
            estimated.
        independent_variable: Indicates which variable in '-expr' is the\
            independent variable. All other symbols are parameters, which are\
            either fixed (constants) or variables to be estimated. Read the values\
            of the independent variable from 1D file.
        parameters: Set fixed value or estimating range for a particular\
            symbol. For a fixed value, it takes the form 'a=3.14'. For an estimated\
            parameter, it takes the form 'q=-sqrt(2):sqrt(2)'. All symbols in\
            '-expr' must have a corresponding '-param' option, EXCEPT for the\
            '-indvar' symbol.
        dependent_data: Read the values of the dependent variable (to be fitted\
            to '-expr') from 1D file. The file must have the same number of rows as\
            the '-indvar' file.
        method: Set the method for fitting: '1' for L1, '2' for L2 (default is\
            L2).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V1dNlfitOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_1D_NLFIT_METADATA)
    cargs = []
    cargs.append("1dNLfit")
    cargs.extend([
        "-expr",
        expression
    ])
    cargs.extend([
        "-indvar",
        independent_variable
    ])
    cargs.extend([
        "-param",
        *parameters
    ])
    cargs.extend([
        "-depdata",
        execution.input_file(dependent_data)
    ])
    if method is not None:
        cargs.extend([
            "-meth",
            str(method)
        ])
    ret = V1dNlfitOutputs(
        root=execution.output_file("."),
        fit_results=execution.output_file("stdout"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V1dNlfitOutputs",
    "V_1D_NLFIT_METADATA",
    "v_1d_nlfit",
]
