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

import typing
import pathlib
from styxdefs import *
import dataclasses

SFA2FIELDSIGN_METADATA = Metadata(
    id="673483cb133e81114140c357c0715b77a189756a.boutiques",
    name="sfa2fieldsign",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class Sfa2fieldsignOutputs(typing.NamedTuple):
    """
    Output object returned when calling `sfa2fieldsign(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    fsig_bin: OutputPathType
    """Intersection of polar and eccentricity thresholded fieldsigns"""
    eccen_masked: OutputPathType
    """Eccentricity angle (rad) volume masked by fieldsign bin"""
    polar_masked: OutputPathType
    """Polar angle (rad) volume masked by fieldsign bin"""
    eccen_masked_mgh: OutputPathType
    """Masked eccentricity angle sampled on the hemisphere surface"""
    polar_masked_mgh: OutputPathType
    """Masked polar angle sampled on the hemisphere surface"""
    fieldsign_masked_mgh: OutputPathType
    """Masked fieldsign map"""


def sfa2fieldsign(
    sfadir: str,
    register_dat: str,
    threshold: float | None = 2,
    fwhm: float | None = 10,
    proj_frac: float | None = 0.5,
    occip: bool = False,
    patch: str | None = None,
    osd: str | None = None,
    lh: bool = False,
    rh: bool = False,
    runner: Runner | None = None,
) -> Sfa2fieldsignOutputs:
    """
    Computes fieldsign map from sfa-sess output. Masks the angle volumes and samples
    them to the surface.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        sfadir: Output directory of sfa-sess.
        register_dat: Registration file.
        threshold: Sigthresh threshold (Default: 2).
        fwhm: Full width at half maximum (FWHM) (Default: 10mm).
        proj_frac: Projection fraction (Default: 0.5).
        occip: Use ?h.occip.patch.flat.
        patch: Use specific patch (?)h.patch.
        osd: Directory under SFA to put output (Default: fieldsign).
        lh: Process left hemisphere only.
        rh: Process right hemisphere only.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Sfa2fieldsignOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(SFA2FIELDSIGN_METADATA)
    cargs = []
    cargs.append("sfa2fieldsign")
    cargs.extend([
        "--sfa",
        sfadir
    ])
    cargs.extend([
        "--reg",
        register_dat
    ])
    if threshold is not None:
        cargs.extend([
            "--thresh",
            str(threshold)
        ])
    if fwhm is not None:
        cargs.extend([
            "--fwhm",
            str(fwhm)
        ])
    if proj_frac is not None:
        cargs.extend([
            "--proj-frac",
            str(proj_frac)
        ])
    if occip:
        cargs.append("--occip")
    if patch is not None:
        cargs.extend([
            "--patch",
            patch
        ])
    if osd is not None:
        cargs.extend([
            "--osd",
            osd
        ])
    if lh:
        cargs.append("--lh")
    if rh:
        cargs.append("--rh")
    ret = Sfa2fieldsignOutputs(
        root=execution.output_file("."),
        fsig_bin=execution.output_file(sfadir + "/[OSD or fieldsign]/fsig.bin.nii"),
        eccen_masked=execution.output_file(sfadir + "/[OSD or fieldsign]/eccen.masked.nii"),
        polar_masked=execution.output_file(sfadir + "/[OSD or fieldsign]/polar.masked.nii"),
        eccen_masked_mgh=execution.output_file(sfadir + "/[OSD or fieldsign]/?h.eccen.masked.mgh"),
        polar_masked_mgh=execution.output_file(sfadir + "/[OSD or fieldsign]/?h.polar.masked.mgh"),
        fieldsign_masked_mgh=execution.output_file(sfadir + "/[OSD or fieldsign]/?h.fieldsign.masked.mgh"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "SFA2FIELDSIGN_METADATA",
    "Sfa2fieldsignOutputs",
    "sfa2fieldsign",
]
