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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_EM_REGISTER_METADATA = Metadata(
    id="9edc027d219877b8b87c7bf356e57518fe060c1a.boutiques",
    name="mri_em_register",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriEmRegisterOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_em_register(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_transform_file: OutputPathType
    """Transform in LTA format"""


def mri_em_register(
    input_volume: InputPathType,
    template_gca: InputPathType,
    output_transform: str,
    distance: float | None = None,
    nomap: bool = False,
    flash: bool = False,
    mask: InputPathType | None = None,
    skull: bool = False,
    uns: float | None = None,
    diag: str | None = None,
    debug_voxel: list[float] | None = None,
    debug_label: float | None = None,
    tr: float | None = None,
    te: float | None = None,
    alpha: float | None = None,
    example: list[InputPathType] | None = None,
    samples: str | None = None,
    fsamples: str | None = None,
    nsamples: str | None = None,
    contrast: bool = False,
    flash_parms: InputPathType | None = None,
    transonly: bool = False,
    write_mean: str | None = None,
    prior: float | None = None,
    spacing: float | None = None,
    scales: float | None = None,
    novar: bool = False,
    dt: float | None = None,
    tol: float | None = None,
    center: bool = False,
    noscale: bool = False,
    noiscale: bool = False,
    num_transforms: float | None = None,
    area: float | None = None,
    nlarea: float | None = None,
    levels: float | None = None,
    intensity: float | None = None,
    reduce: float | None = None,
    n_samples: float | None = None,
    norm: str | None = None,
    trans: float | None = None,
    steps: float | None = None,
    long_reg: str | None = None,
    cpfile: InputPathType | None = None,
    translation_vector: list[float] | None = None,
    rotation_vector: list[float] | None = None,
    xform: str | None = None,
    blur: float | None = None,
    diagno: bool = False,
    s: float | None = None,
    max_angle: float | None = None,
    niters: float | None = None,
    write_iters: float | None = None,
    ctl_point_pct: float | None = None,
    momentum: float | None = None,
    threads: float | None = None,
    runner: Runner | None = None,
) -> MriEmRegisterOutputs:
    """
    This program creates a transform in lta format.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_volume: Input brain volume.
        template_gca: Template GCA file.
        output_transform: Output transform name.
        distance: Distance.
        nomap: No map.
        flash: Use FLASH forward model to predict intensity values.
        mask: Use volname as a mask.
        skull: Align to atlas containing skull (uns=5).
        uns: Align to atlas containing skull setting unknown_nbr_spacing =\
            nbrspacing.
        diag: Open diagfile for writing.
        debug_voxel: Debug voxel (x, y, z).
        debug_label: Debug label (label).
        tr: Use TR msec.
        te: Use TE msec.
        alpha: Use alpha degrees.
        example: Use T1 and seg as example T1 and segmentations respectively.
        samples: Write control points to fname.
        fsamples: Write transformed control points to fname.
        nsamples: Write transformed normalization control points to fname.
        contrast: Use contrast to find labels.
        flash_parms: Use FLASH forward model and tissue parms in parameterfile\
            to predict intensity values.
        transonly: Only compute translation parameters.
        write_mean: Write GCA means to fname.
        prior: Use prior threshold min_prior.
        spacing: Use max GCA spacing.
        scales: Find optimal linear transform over int scales.
        novar: Do not use variance estimates.
        dt: DT parameter.
        tol: Tolerance.
        center: Use GCA centroid as origin of transform.
        noscale: Disable scaling.
        noiscale: Disable intensity scaling.
        num_transforms: Find a total of num_xforms linear transforms.
        area: Area.
        nlarea: Non-linear area.
        levels: Levels.
        intensity: Intensity.
        reduce: Reduce input images nreductions times before aligning.
        n_samples: Using n samples of GCA.
        norm: Normalize intensity and write to fname.
        trans: Setting max translation search range to be max_trans.
        steps: Taking max_angles angular steps.
        long_reg: Longitudinal: read previously computed atlas xform and apply\
            registration long_reg.
        cpfile: Read manually defined control points from cpfile.
        translation_vector: Translation vector (tx, ty, tz).
        rotation_vector: Rotation vector (rx, ry, rz).
        xform: Using previously computed transform xform.
        blur: Blurring input image with sigma=blur_sigma.
        diagno: Diago flag (unspecified function).
        s: Max angles.
        max_angle: Max angle for rotational search in radians (def=15 deg).
        niters: Niterations = niters.
        write_iters: Write iterations = write_iters.
        ctl_point_pct: Use top pct percent wm points as control points.
        momentum: Set momentum.
        threads: Number of threads (nompthreads).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriEmRegisterOutputs`).
    """
    if example is not None and (len(example) != 2): 
        raise ValueError(f"Length of 'example' must be 2 but was {len(example)}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_EM_REGISTER_METADATA)
    cargs = []
    cargs.append("mri_em_register")
    cargs.append(execution.input_file(input_volume))
    cargs.append(execution.input_file(template_gca))
    cargs.append(output_transform)
    if distance is not None:
        cargs.extend([
            "-dist",
            str(distance)
        ])
    if nomap:
        cargs.append("-nomap")
    if flash:
        cargs.append("-flash")
    if mask is not None:
        cargs.extend([
            "-mask",
            execution.input_file(mask)
        ])
    if skull:
        cargs.append("-skull")
    if uns is not None:
        cargs.extend([
            "-uns",
            str(uns)
        ])
    if diag is not None:
        cargs.extend([
            "-diag",
            diag
        ])
    if debug_voxel is not None:
        cargs.extend([
            "-debug_voxel",
            *map(str, debug_voxel)
        ])
    if debug_label is not None:
        cargs.extend([
            "-debug_label",
            str(debug_label)
        ])
    if tr is not None:
        cargs.extend([
            "-tr",
            str(tr)
        ])
    if te is not None:
        cargs.extend([
            "-te",
            str(te)
        ])
    if alpha is not None:
        cargs.extend([
            "-alpha",
            str(alpha)
        ])
    if example is not None:
        cargs.extend([
            "-example",
            *[execution.input_file(f) for f in example]
        ])
    if samples is not None:
        cargs.extend([
            "-samples",
            samples
        ])
    if fsamples is not None:
        cargs.extend([
            "-fsamples",
            fsamples
        ])
    if nsamples is not None:
        cargs.extend([
            "-nsamples",
            nsamples
        ])
    if contrast:
        cargs.append("-contrast")
    if flash_parms is not None:
        cargs.extend([
            "-flash_parms",
            execution.input_file(flash_parms)
        ])
    if transonly:
        cargs.append("-transonly")
    if write_mean is not None:
        cargs.extend([
            "-write_mean",
            write_mean
        ])
    if prior is not None:
        cargs.extend([
            "-prior",
            str(prior)
        ])
    if spacing is not None:
        cargs.extend([
            "-spacing",
            str(spacing)
        ])
    if scales is not None:
        cargs.extend([
            "-scales",
            str(scales)
        ])
    if novar:
        cargs.append("-novar")
    if dt is not None:
        cargs.extend([
            "-dt",
            str(dt)
        ])
    if tol is not None:
        cargs.extend([
            "-tol",
            str(tol)
        ])
    if center:
        cargs.append("-center")
    if noscale:
        cargs.append("-noscale")
    if noiscale:
        cargs.append("-noiscale")
    if num_transforms is not None:
        cargs.extend([
            "-num",
            str(num_transforms)
        ])
    if area is not None:
        cargs.extend([
            "-area",
            str(area)
        ])
    if nlarea is not None:
        cargs.extend([
            "-nlarea",
            str(nlarea)
        ])
    if levels is not None:
        cargs.extend([
            "-levels",
            str(levels)
        ])
    if intensity is not None:
        cargs.extend([
            "-intensity",
            str(intensity)
        ])
    if reduce is not None:
        cargs.extend([
            "-reduce",
            str(reduce)
        ])
    if n_samples is not None:
        cargs.extend([
            "-nsamples",
            str(n_samples)
        ])
    if norm is not None:
        cargs.extend([
            "-norm",
            norm
        ])
    if trans is not None:
        cargs.extend([
            "-trans",
            str(trans)
        ])
    if steps is not None:
        cargs.extend([
            "-steps",
            str(steps)
        ])
    if long_reg is not None:
        cargs.extend([
            "-l",
            long_reg
        ])
    if cpfile is not None:
        cargs.extend([
            "-f",
            execution.input_file(cpfile)
        ])
    if translation_vector is not None:
        cargs.extend([
            "-d",
            *map(str, translation_vector)
        ])
    if rotation_vector is not None:
        cargs.extend([
            "-r",
            *map(str, rotation_vector)
        ])
    if xform is not None:
        cargs.extend([
            "-t",
            xform
        ])
    if blur is not None:
        cargs.extend([
            "-b",
            str(blur)
        ])
    if diagno:
        cargs.append("-v")
    if s is not None:
        cargs.extend([
            "-s",
            str(s)
        ])
    if max_angle is not None:
        cargs.extend([
            "-max_angle",
            str(max_angle)
        ])
    if niters is not None:
        cargs.extend([
            "-n",
            str(niters)
        ])
    if write_iters is not None:
        cargs.extend([
            "-w",
            str(write_iters)
        ])
    if ctl_point_pct is not None:
        cargs.extend([
            "-p",
            str(ctl_point_pct)
        ])
    if momentum is not None:
        cargs.extend([
            "-m",
            str(momentum)
        ])
    if threads is not None:
        cargs.extend([
            "-threads",
            str(threads)
        ])
    ret = MriEmRegisterOutputs(
        root=execution.output_file("."),
        output_transform_file=execution.output_file(output_transform + ".lta"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_EM_REGISTER_METADATA",
    "MriEmRegisterOutputs",
    "mri_em_register",
]
