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

import typing
import pathlib
from styxdefs import *
import dataclasses

RETRO_TS_PY_METADATA = Metadata(
    id="3a8f942af6b333e80cee0dd94a9b9a446d4fee85.boutiques",
    name="RetroTS.py",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class RetroTsPyOutputs(typing.NamedTuple):
    """
    Output object returned when calling `retro_ts_py(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_file: OutputPathType | None
    """Output file containing respiratory and cardiac regressors"""


def retro_ts_py(
    num_slices: float,
    volume_tr: float,
    resp_file: InputPathType | None = None,
    card_file: InputPathType | None = None,
    phys_fs: float | None = None,
    phys_file: InputPathType | None = None,
    phys_json: InputPathType | None = None,
    prefix: str | None = None,
    rvt_shifts: str | None = None,
    rvt_out: bool = False,
    resp_cutoff_freq: float | None = None,
    cardiac_cutoff_freq: float | None = None,
    cardiac_out: bool = False,
    respiration_out: bool = False,
    interp_style: str | None = None,
    fir_order: float | None = None,
    quiet: bool = False,
    demo: bool = False,
    show_graphs: bool = False,
    debug: bool = False,
    slice_offset: str | None = None,
    slice_major: float | None = None,
    slice_order: str | None = None,
    zero_phase_offset: bool = False,
    legacy_transform: float | None = None,
    runner: Runner | None = None,
) -> RetroTsPyOutputs:
    """
    Creates slice-based regressors for regressing out components of heart rate,
    respiration, and respiration volume per time using independent data files or
    BIDS formatted files.
    
    Author: AFNI Team
    
    URL: https://afni.nimh.nih.gov/pub/dist/doc/program_help/RetroTS.py.html
    
    Args:
        num_slices: Number of slices.
        volume_tr: Volume TR in seconds.
        resp_file: Respiration data file.
        card_file: Cardiac data file.
        phys_fs: Physiological signal sampling frequency in Hz.
        phys_file: BIDS formatted physio file in tab-separated format, can be\
            gzipped.
        phys_json: BIDS formatted physio metadata json file. If not specified,\
            the json corresponding to the phys_file will be loaded.
        prefix: Prefix of output file.
        rvt_shifts: Vector of shifts in seconds of RVT signal. (default is\
            [0:5:20]).
        rvt_out: Flag for writing RVT regressors (default is 1).
        resp_cutoff_freq: Cut-off frequency in Hz for respiratory lowpass\
            filter (default 3 Hz).
        cardiac_cutoff_freq: Cut-off frequency in Hz for cardiac lowpass filter\
            (default 3 Hz).
        cardiac_out: Flag for writing Cardiac regressors (default is 1).
        respiration_out: Flag for writing Respiratory regressors (default is 1).
        interp_style: Resampling kernel (default is 'linear').
        fir_order: Order of FIR filter (default is 40).
        quiet: Show talkative progress as the program runs (default is 1).
        demo: Run demonstration of RetroTS (default is 0).
        show_graphs: Show graphs (default is unset; set with any parameter to\
            view).
        debug: Drop into pdb upon an exception (default is False).
        slice_offset: Vector of slice acquisition time offsets in seconds\
            (default is equivalent of alt+z).
        slice_major: Unknown parameter (default is 1).
        slice_order: Slice timing information in seconds. (default is alt+z).
        zero_phase_offset: Zero phase offset flag.
        legacy_transform: Specify the version of the original Matlab code's\
            transformation (default is 0).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `RetroTsPyOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(RETRO_TS_PY_METADATA)
    cargs = []
    cargs.append("python")
    cargs.append("RetroTS.py")
    if resp_file is not None:
        cargs.extend([
            "-r",
            execution.input_file(resp_file)
        ])
    if card_file is not None:
        cargs.extend([
            "-c",
            execution.input_file(card_file)
        ])
    if phys_fs is not None:
        cargs.extend([
            "-p",
            str(phys_fs)
        ])
    cargs.extend([
        "-n",
        str(num_slices)
    ])
    cargs.extend([
        "-v",
        str(volume_tr)
    ])
    if phys_file is not None:
        cargs.extend([
            "-phys_file",
            execution.input_file(phys_file)
        ])
    if phys_json is not None:
        cargs.extend([
            "-phys_json",
            execution.input_file(phys_json)
        ])
    if prefix is not None:
        cargs.extend([
            "-prefix",
            prefix
        ])
    if rvt_shifts is not None:
        cargs.extend([
            "-rvt_shifts",
            rvt_shifts
        ])
    if rvt_out:
        cargs.append("-rvt_out")
    if resp_cutoff_freq is not None:
        cargs.extend([
            "-respiration_cutoff_frequency",
            str(resp_cutoff_freq)
        ])
    if cardiac_cutoff_freq is not None:
        cargs.extend([
            "-cardiac_cutoff_frequency",
            str(cardiac_cutoff_freq)
        ])
    if cardiac_out:
        cargs.append("-cardiac_out")
    if respiration_out:
        cargs.append("-respiration_out")
    if interp_style is not None:
        cargs.extend([
            "-interpolation_style",
            interp_style
        ])
    if fir_order is not None:
        cargs.extend([
            "-fir_order",
            str(fir_order)
        ])
    if quiet:
        cargs.append("-quiet")
    if demo:
        cargs.append("-demo")
    if show_graphs:
        cargs.append("-show_graphs")
    if debug:
        cargs.append("-debug")
    if slice_offset is not None:
        cargs.extend([
            "-slice_offset",
            slice_offset
        ])
    if slice_major is not None:
        cargs.extend([
            "-slice_major",
            str(slice_major)
        ])
    if slice_order is not None:
        cargs.extend([
            "-slice_order",
            slice_order
        ])
    if zero_phase_offset:
        cargs.append("-zero_phase_offset")
    if legacy_transform is not None:
        cargs.extend([
            "-legacy_transform",
            str(legacy_transform)
        ])
    ret = RetroTsPyOutputs(
        root=execution.output_file("."),
        output_file=execution.output_file(prefix + ".slibase.1D") if (prefix is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "RETRO_TS_PY_METADATA",
    "RetroTsPyOutputs",
    "retro_ts_py",
]
