Skip to content

Alignment Result

alignment_result

AlignmentResult dataclass

AlignmentResult(
    name: str = "Alignment Result",
    position_parameters: AlignmentParameters = AlignmentParameters(),
    rotation_parameters: SensorRotationParameters = SensorRotationParameters(),
    estimation_of: AlignmentEstimationSettings = AlignmentEstimationSettings(),
    converged: bool = True,
)

Class to store the result of an alignment.

Attributes:

  • name (str) –

    Name of the result.

  • position_parameters (AlignmentParameters) –

    Estimated position alignment parameters.

  • rotation_parameters (SensorRotationParameters) –

    Estimated rotation alignment parameters.

  • estimation_of (AlignmentEstimationSettings) –

    Settings defining which parameters were estimated.

  • converged (bool) –

    Whether the estimation converged.

to_file

to_file(filename: str) -> None

Save the result to a file.

Parameters:

  • filename (str) –

    Path to the file.

Source code in trajectopy\results\alignment_result.py
def to_file(self, filename: str) -> None:
    """
    Save the result to a file.

    Args:
        filename (str): Path to the file.
    """
    if self.position_parameters is None:
        raise ValueError("No estimated parameters available!")

    with open(filename, "a", newline="\n", encoding="utf-8") as file:
        file.write(f"#name {self.name}\n")

    self.position_parameters.to_dataframe().to_csv(
        filename, header=False, index=False, mode="a", float_format="%.15f"
    )
    self.rotation_parameters.to_file(filename=filename)

from_file classmethod

from_file(filename: str) -> AlignmentResult

Load the result from a file.

Parameters:

  • filename (str) –

    Path to the file.

Returns:

Source code in trajectopy\results\alignment_result.py
@classmethod
def from_file(cls, filename: str) -> "AlignmentResult":
    """
    Load the result from a file.

    Args:
        filename (str): Path to the file.

    Returns:
        AlignmentResult: The loaded result.
    """
    header_data = HeaderData.from_file(filename)
    estimated_parameters = AlignmentParameters.from_file(filename)
    sensor_rot_parameters = SensorRotationParameters.from_file(filename)
    return cls(
        name=str(header_data.data.get("name", "Alignment")),
        position_parameters=estimated_parameters,
        estimation_of=AlignmentEstimationSettings.from_bool_list(
            estimated_parameters.enabled_bool_list + sensor_rot_parameters.enabled_bool_list
        ),
        rotation_parameters=sensor_rot_parameters,
    )