Skip to content

Commit

Permalink
Switch to seconds for creation ts, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
malconsei committed Sep 13, 2023
1 parent 07092af commit e7ff738
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion mapillary_tools/exiftool_read_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _aggregate_float_values_same_length(
gps_fix=None,
gps_precision=None,
gps_ground_speed=ground_speed,
unix_timestamp_ms=int(timestamp * 1000),
unix_timestamp=timestamp,
)
)

Expand Down
10 changes: 9 additions & 1 deletion mapillary_tools/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

@dataclasses.dataclass(order=True)
class Point:
"""
5-dimensional point. Its coordinates will also be dumped to the JSON description.
"""

# For reducing object sizes
# dataclass(slots=True) not available until 3.10
__slots__ = (
Expand All @@ -41,11 +45,15 @@ class GPSFix(Enum):

@dataclasses.dataclass
class GpsPoint(Point):
"""
Extends Point with GPS data for filtering etc.
"""

gps_fix: T.Optional[GPSFix] = None
gps_precision: T.Optional[float] = None
gps_ground_speed: T.Optional[float] = None
unix_timestamp_ms: T.Optional[int] = None
gps_horizontal_accuracy: T.Optional[float] = None
unix_timestamp: T.Optional[int] = None


def _ecef_from_lla_DEPRECATED(
Expand Down
1 change: 1 addition & 0 deletions mapillary_tools/geotag/blackvue_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _parse_gps_box(gps_data: bytes) -> T.Generator[geo.GpsPoint, None, None]:
lon=nmea.longitude,
alt=nmea.altitude,
angle=None,
unix_timestamp=int(epoch_ms / 1000),
)


Expand Down
4 changes: 1 addition & 3 deletions mapillary_tools/geotag/camm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ def _parse_point_from_sample(
lon=box.data.longitude,
alt=box.data.altitude,
angle=None,
unix_timestamp_ms=int(
_gps_timestamp_to_unix(box.data.time_gps_epoch) * 1000
),
unix_timestamp=int(_gps_timestamp_to_unix(box.data.time_gps_epoch)),
gps_fix=geo.GPSFix(box.data.gps_fix_type),
gps_ground_speed=speed,
gps_horizontal_accuracy=box.data.horizontal_accuracy,
Expand Down
4 changes: 1 addition & 3 deletions mapillary_tools/geotag/geotag_images_from_gpx_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ def parse_gpx(gpx_file: Path) -> T.List[Track]:
lon=point.longitude,
alt=point.elevation,
angle=None,
gps_fix=None,
gps_precision=None,
gps_ground_speed=point.speed,
unix_timestamp_ms=int(time * 1000),
unix_timestamp=int(time),
)
)

Expand Down
5 changes: 1 addition & 4 deletions mapillary_tools/geotag/geotag_images_from_nmea_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def get_lat_lon_time_from_nmea(nmea_file: Path) -> T.List[geo.GpsPoint]:
lon=lon,
alt=alt,
angle=None,
unix_timestamp_ms=int(time * 1000),
gps_fix=None,
gps_ground_speed=None,
gps_precision=None,
unix_timestamp=int(time),
)
)

Expand Down
8 changes: 4 additions & 4 deletions mapillary_tools/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class VideoMetadata:
points: T.Sequence[geo.Point]
make: T.Optional[str] = None
model: T.Optional[str] = None
last_unix_ts: T.Optional[int] = None # GPS time of the last point as Unix ts
last_unix_ts: T.Optional[int] = None # GPS time of the last point as Unix ts

def update_md5sum(self) -> None:
if self.md5sum is None:
Expand Down Expand Up @@ -332,8 +332,8 @@ def describe_error_metadata(
},
"MAPLastUnixTimestamp": {
"type": "integer",
"description": "UNIX timestamp of the last GPS point"
}
"description": "UNIX timestamp of the last GPS point",
},
},
"required": [
"MAPGPSTrack",
Expand Down Expand Up @@ -602,7 +602,7 @@ def _from_video_desc(desc: VideoDescription) -> VideoMetadata:
points=[_decode_point(entry) for entry in desc["MAPGPSTrack"]],
make=desc.get("MAPDeviceMake"),
model=desc.get("MAPDeviceModel"),
last_unix_ts=desc.get("MAPLastUnixTimestamp")
last_unix_ts=desc.get("MAPLastUnixTimestamp"),
)


Expand Down
6 changes: 3 additions & 3 deletions mapillary_tools/video_data_extraction/extract_video_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def process_file(self, file: Path) -> VideoMetadataOrError:
{**log_vars, "e": e},
)

last_ts = points[-1].unix_timestamp_ms if len(points) > 0 else None
last_unix_ts = int(last_ts/1000) if last_ts else None
last_ts = points[-1].unix_timestamp if len(points) > 0 else None
last_ts_int = int(last_ts / 1000) if last_ts else None

# After trying all parsers, return the points if we found any, otherwise
# the last exception thrown or a default one.
Expand All @@ -99,7 +99,7 @@ def process_file(self, file: Path) -> VideoMetadataOrError:
points=self._gps_points_to_points(points),
make=make,
model=model,
last_unix_ts=last_unix_ts
last_unix_ts=last_ts_int,
)
video_metadata.update_md5sum()
return video_metadata
Expand Down
21 changes: 18 additions & 3 deletions tests/unit/test_blackvue_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,27 @@ def test_parse_points():
assert x is not None
assert [
geo.GpsPoint(
time=0.0, lat=38.8861575, lon=-76.99239516666667, alt=10.2, angle=None
time=0.0,
lat=38.8861575,
lon=-76.99239516666667,
alt=10.2,
angle=None,
unix_timestamp=1623057129,
),
geo.GpsPoint(
time=0.968, lat=38.88615816666667, lon=-76.992434, alt=7.7, angle=None
time=0.968,
lat=38.88615816666667,
lon=-76.992434,
alt=7.7,
angle=None,
unix_timestamp=1623057130,
),
geo.GpsPoint(
time=0.968, lat=38.88615816666667, lon=-76.992434, alt=7.7, angle=None
time=0.968,
lat=38.88615816666667,
lon=-76.992434,
alt=7.7,
angle=None,
unix_timestamp=1623057130,
),
] == list(x)

0 comments on commit e7ff738

Please sign in to comment.