diff --git a/leads/data.py b/leads/data.py index 8f3a274..40dc1db 100644 --- a/leads/data.py +++ b/leads/data.py @@ -2,7 +2,7 @@ from time import time as _time from typing import override as _override, Any as _Any -from numpy import radians as _radians, degrees as _degrees, cos as _cos +from numpy import radians as _radians, degrees as _degrees, cos as _cos, sqrt as _sqrt class Serializable(object): @@ -161,6 +161,18 @@ def meters2dlon(meters: float, lat: float) -> float: return _degrees(meters / 6378137 / _cos(_radians(lat))) +def distance_between(lat_0: float, lon_0: float, lat: float, lon: float) -> float: + """ + Calculate the distance between two locations on the Earth. + :param lat_0: the latitude of the first location + :param lon_0: the longitude of the first location + :param lat: the latitude of the second location + :param lon: the longitude of the second location + :return: + """ + return _sqrt(dlon2meters(lon - lon_0, .5 * (lat_0 + lat)) ** 2 + dlat2meters(lat - lat_0) ** 2) + + def format_duration(duration: float) -> str: """ Wrap the duration into a formatted string. diff --git a/leads/data_persistence/analyzer/inference.py b/leads/data_persistence/analyzer/inference.py index e0dbb54..72dfeb6 100644 --- a/leads/data_persistence/analyzer/inference.py +++ b/leads/data_persistence/analyzer/inference.py @@ -1,8 +1,9 @@ from abc import ABCMeta as _ABCMeta, abstractmethod as _abstractmethod from typing import Any as _Any, override as _override, Generator as _Generator, Literal as _Literal +from leads.data import distance_between from leads.data_persistence.analyzer.utils import time_invalid, speed_invalid, acceleration_invalid, \ - mileage_invalid, latitude_invalid, longitude_invalid, distance_between + mileage_invalid, latitude_invalid, longitude_invalid from leads.data_persistence.core import CSVDataset, DEFAULT_HEADER, VISUAL_HEADER_ONLY @@ -239,6 +240,7 @@ class VisualDataRealignmentByLatency(Inference): Offset the delay introduced by camera recording and video encoding so that the sensor data and the picture of the same frame match. """ + def __init__(self, *channels: _Literal["front", "left", "right", "rear"]) -> None: super().__init__((0, 1), VISUAL_HEADER_ONLY) self._channels: tuple[_Literal["front", "left", "right", "rear"], ...] = channels if channels else ( diff --git a/leads/data_persistence/analyzer/utils.py b/leads/data_persistence/analyzer/utils.py index a8e6fee..46f9adb 100644 --- a/leads/data_persistence/analyzer/utils.py +++ b/leads/data_persistence/analyzer/utils.py @@ -1,8 +1,5 @@ from typing import Any as _Any -from leads.data import dlat2meters, dlon2meters -from .._computational import sqrt as _sqrt - def time_invalid(o: _Any) -> bool: return not isinstance(o, int) @@ -30,15 +27,3 @@ def longitude_invalid(o: _Any) -> bool: def latency_invalid(o: _Any) -> bool: return not isinstance(o, int | float) - - -def distance_between(lat_0: float, lon_0: float, lat: float, lon: float) -> float: - """ - Calculate the distance between two locations on the Earth. - :param lat_0: the latitude of the first location - :param lon_0: the longitude of the first location - :param lat: the latitude of the second location - :param lon: the longitude of the second location - :return: - """ - return _sqrt(dlon2meters(lon - lon_0, .5 * (lat_0 + lat)) ** 2 + dlat2meters(lat - lat_0) ** 2)