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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_CA_NORMALIZE_METADATA = Metadata(
    id="822a8e4a63033035b2c8f0da0858f4e52e7344bd.boutiques",
    name="mri_ca_normalize",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriCaNormalizeOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_ca_normalize(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    normalized_output: OutputPathType
    """Normalized output volume in mgh format."""


def mri_ca_normalize(
    input_brain_volumes: list[InputPathType],
    atlas_file: InputPathType,
    xform_file: InputPathType,
    output_volumes: list[str],
    seg_file: InputPathType | None = None,
    sigma_value: float | None = None,
    fsamples_file: InputPathType | None = None,
    dilate_iters: float | None = None,
    nsamples_file: InputPathType | None = None,
    mask_vol: InputPathType | None = None,
    control_points_file: InputPathType | None = None,
    fonly_file: InputPathType | None = None,
    diag_file: InputPathType | None = None,
    debug_voxel_coords: list[float] | None = None,
    debug_node_coords: list[float] | None = None,
    tr_value: float | None = None,
    te_value: float | None = None,
    alpha_value: float | None = None,
    example_mri_vol: InputPathType | None = None,
    extra_norm_pctl: float | None = None,
    prior_threshold: float | None = None,
    n_regions: float | None = None,
    verbose_value: float | None = None,
    top_percent: float | None = None,
    novar_flag: bool = False,
    renorm_file: InputPathType | None = None,
    flash_flag: bool = False,
    runner: Runner | None = None,
) -> MriCaNormalizeOutputs:
    """
    This program creates a normalized volume using the brain volume and an input gca
    file.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_brain_volumes: Input brain volume(s). Can specify multiple\
            inputs.
        atlas_file: Atlas file in GCA format.
        xform_file: Transform file in LTA format.
        output_volumes: Output volume(s) in either mgh or mgz format. Can\
            specify multiple outputs.
        seg_file: Aseg file to help normalization.
        sigma_value: Smoothing sigma for bias field if control points specified\
            (default=4).
        fsamples_file: Write control points to filename.
        dilate_iters: Dilate the brain mask niters times before masking.
        nsamples_file: Write transformed normalization control points to\
            filename.
        mask_vol: Use mri_vol to mask input.
        control_points_file: Define control points from filename.
        fonly_file: Only use control points from filename.
        diag_file: Write to log file.
        debug_voxel_coords: Debug voxel. Needs x, y, z coordinates.
        debug_node_coords: Debug node. Needs x, y, z coordinates.
        tr_value: Set TR in msec.
        te_value: Set TE in msec.
        alpha_value: Set alpha in radians.
        example_mri_vol: Use T1 (mri_vol) and segmentation as example.
        extra_norm_pctl: Use 1+pct and 1-pct to widen the range of T1 values.
        prior_threshold: Use prior threshold t (default=.6).
        n_regions: Use n regions/struct for normalization.
        verbose_value: Used for debugging and diagnostics.
        top_percent: Use top p percent (default=.25) white matter points as\
            control points.
        novar_flag: Do not use variance estimates.
        renorm_file: Renormalize using predicted intensity values in mri_vol.
        flash_flag: Use FLASH forward model to predict intensity values.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriCaNormalizeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_CA_NORMALIZE_METADATA)
    cargs = []
    cargs.append("mri_ca_normalize")
    cargs.extend([execution.input_file(f) for f in input_brain_volumes])
    cargs.append(execution.input_file(atlas_file))
    cargs.append(execution.input_file(xform_file))
    cargs.extend(output_volumes)
    if seg_file is not None:
        cargs.extend([
            "-seg",
            execution.input_file(seg_file)
        ])
    if sigma_value is not None:
        cargs.extend([
            "-sigma",
            str(sigma_value)
        ])
    if fsamples_file is not None:
        cargs.extend([
            "-fsamples",
            execution.input_file(fsamples_file)
        ])
    if dilate_iters is not None:
        cargs.extend([
            "-dilate",
            str(dilate_iters)
        ])
    if nsamples_file is not None:
        cargs.extend([
            "-nsamples",
            execution.input_file(nsamples_file)
        ])
    if mask_vol is not None:
        cargs.extend([
            "-mask",
            execution.input_file(mask_vol)
        ])
    if control_points_file is not None:
        cargs.extend([
            "-f",
            execution.input_file(control_points_file)
        ])
    if fonly_file is not None:
        cargs.extend([
            "-fonly",
            execution.input_file(fonly_file)
        ])
    if diag_file is not None:
        cargs.extend([
            "-diag",
            execution.input_file(diag_file)
        ])
    if debug_voxel_coords is not None:
        cargs.extend([
            "-debug_voxel",
            *map(str, debug_voxel_coords)
        ])
    if debug_node_coords is not None:
        cargs.extend([
            "-debug_node",
            *map(str, debug_node_coords)
        ])
    if tr_value is not None:
        cargs.extend([
            "-tr",
            str(tr_value)
        ])
    if te_value is not None:
        cargs.extend([
            "-te",
            str(te_value)
        ])
    if alpha_value is not None:
        cargs.extend([
            "-alpha",
            str(alpha_value)
        ])
    if example_mri_vol is not None:
        cargs.extend([
            "-example",
            execution.input_file(example_mri_vol)
        ])
    if extra_norm_pctl is not None:
        cargs.extend([
            "-extra_norm",
            str(extra_norm_pctl)
        ])
    if prior_threshold is not None:
        cargs.extend([
            "-prior",
            str(prior_threshold)
        ])
    if n_regions is not None:
        cargs.extend([
            "-n",
            str(n_regions)
        ])
    if verbose_value is not None:
        cargs.extend([
            "-v",
            str(verbose_value)
        ])
    if top_percent is not None:
        cargs.extend([
            "-p",
            str(top_percent)
        ])
    if novar_flag:
        cargs.append("-novar")
    if renorm_file is not None:
        cargs.extend([
            "-renorm",
            execution.input_file(renorm_file)
        ])
    if flash_flag:
        cargs.append("-flash")
    ret = MriCaNormalizeOutputs(
        root=execution.output_file("."),
        normalized_output=execution.output_file("output.mgh"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_CA_NORMALIZE_METADATA",
    "MriCaNormalizeOutputs",
    "mri_ca_normalize",
]
