Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/command_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ give an `--overwrite_*` option.
| `--interpolation_use_gpx_start_time` | | Place the first image, or the start of a video, at the first point of the track. |
| `--offset_time SECONDS` | 0 | Seconds added to image capture times after geotagging. Does not move images. |
| `--offset_angle DEGREES` | 0 | Degrees added to image directions. |
| `--use_file_time_as_capture_time` | | Give an image with a GPS position but no capture time the earlier of its file modification and creation times. See the gotchas below. |
| `--no_file_time_as_capture_time` | | Fail an image with a GPS position but no capture time, instead of giving it its file time. See the gotchas below. |
| `--interpolate_directions` | | Point each image at the next one, instead of using the direction from EXIF. |
| `--cutoff_time`, `--cutoff_distance` | 60 s, 100 m | Where to split sequences. |
| `--duplicate_distance`, `--duplicate_angle` | 0.1 m, 5° | When an image counts as a duplicate of the one before it. `--duplicate_angle 360` ignores direction. |
Expand Down Expand Up @@ -201,13 +201,13 @@ Gotchas:
change the capture time that is uploaded: to fix a camera clock against a GPX, use
`--interpolation_offset_time` alone.
- The `--overwrite_*` options modify your original images.
- An image with a GPS position of its own but no capture time that any source can read fails, with a message that
says how to fix it. With `--use_file_time_as_capture_time`, it gets the earlier of its file modification and
creation times instead (on Linux, the modification time), with a warning: a `MapillaryFileTimeWarning` in the
process report. A downloaded, exported or copied file has the time of the copy, and images written in one go get
times within seconds of each other: a sequence of them is uploaded with the time of the copy, or fails as too fast
(`MapillaryCaptureSpeedTooFastError`, which then says that the times are file times). An image placed on a GPX or
NMEA track still fails without a capture time.
- An image with a GPS position of its own but no capture time that any source can read gets the earlier of its
file modification and creation times (on Linux, the modification time), with a warning: a
`MapillaryFileTimeWarning` in the process report. A downloaded, exported or copied file has the time of the copy,
and images written in one go get times within seconds of each other: a sequence of them is uploaded with the time
of the copy, or fails as too fast (`MapillaryCaptureSpeedTooFastError`, which then says that the times are file
times). With `--no_file_time_as_capture_time`, such an image fails instead. An image placed on a GPX or NMEA
track always fails without a capture time.
- Images whose only date is a placeholder, or before 1970, fail. So do images whose EXIF GPS latitude or longitude
has minutes or seconds above 60 (`MapillaryInvalidGPSCoordinateError`), with `exiftool_runtime` and
`exiftool_xml` too (ExifTool reads 47° 75' as 48° 15'), unless a `gpx` or `nmea` source geotags them.
Expand Down Expand Up @@ -483,7 +483,7 @@ mapillary_tools video_process VIDEO_IMPORT_PATH [IMPORT_PATH] [OPTIONS]
```

Runs [`sample_video`](#sample_video), then [`process`](#process) on the frames, and takes the options of both,
but `--use_file_time_as_capture_time`: the frames get their times from the video.
but `--no_file_time_as_capture_time`: the frames get their times from the video, never from the files.
The description file goes into `IMPORT_PATH` by default.

```sh
Expand Down
15 changes: 9 additions & 6 deletions mapillary_tools/commands/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def add_basic_arguments(
):
"""
The options of process. For **video_frames** (video_process), without
--use_file_time_as_capture_time: the frames get their times from the
video
--no_file_time_as_capture_time, and without file times: the frames get
their times from the video
"""
geotag_gpx_based_sources: list[str] = [
SourceType.GPX.value,
Expand Down Expand Up @@ -183,11 +183,14 @@ def add_basic_arguments(
required=False,
)
if not video_frames:
# On by default. Without the option (video_process), the default of
# process_geotag_properties applies: no file times
group_geotagging.add_argument(
"--use_file_time_as_capture_time",
help="For an image that has a GPS position but no capture time in its metadata, use the earlier of its file modification and creation times (only the modification time on Linux) as its capture time, with a warning. A downloaded, exported or copied file has the time of the copy, which is not when the image was taken: use this only if the file times are when the images were taken. Images placed on a GPX or NMEA track still need a capture time.",
action="store_true",
default=False,
"--no_file_time_as_capture_time",
dest="use_file_time_as_capture_time",
help="Fail an image that has a GPS position but no capture time in its metadata. By default, such an image gets the earlier of its file modification and creation times (only the modification time on Linux) as its capture time, with a warning. A downloaded, exported or copied file has the time of the copy, which is not when the image was taken. Images placed on a GPX or NMEA track always need a capture time.",
action="store_false",
default=True,
required=False,
)
group_geotagging.add_argument(
Expand Down
13 changes: 6 additions & 7 deletions mapillary_tools/geotag/image_extractors/exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ class ImageEXIFExtractor(BaseImageExtractor):
(0, 0), for a geotag source that positions it by its capture time (on a
GPX track, say) instead.

With **use_file_time** (--use_file_time_as_capture_time), an image with a
position but no capture time is extracted with the earlier of its file
modification and creation times, and a MapillaryFileTimeWarning that says
so: process() keeps it only if no other geotag source geotags the image.
With **use_file_time** (process, unless --no_file_time_as_capture_time),
an image with a position but no capture time is extracted with the earlier
of its file modification and creation times, and a MapillaryFileTimeWarning
that says so: process() keeps it only if no other geotag source geotags the
image.
Never with **skip_lonlat_error**, where the capture time positions the
image, and a file time would position it wrongly, without a word.
"""
Expand Down Expand Up @@ -184,9 +185,7 @@ def extract(self) -> types.ImageMetadata:
raise exceptions.MapillaryGeoTaggingError(
"Unable to extract timestamp from the image: it has a GPS "
"position but no capture time. Write the capture time into "
"the image (with ExifTool, for example), or use "
"--use_file_time_as_capture_time if the time of the file is "
"when the image was taken"
"the image (with ExifTool, for example)"
)
file_time = self._file_time()
if file_time is None:
Expand Down
4 changes: 2 additions & 2 deletions mapillary_tools/geotag/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class SourceOption:
named_video_type: types.FileType | None = None

# Whether an image with a GPS position but no capture time gets its file
# time (--use_file_time_as_capture_time). Read by the sources that read the
# position of an image from the image itself. Set by
# time (process, unless --no_file_time_as_capture_time). Read by the
# sources that read the position of an image from the image itself. Set by
# process_geotag_properties, and not in the JSON schema
use_file_time: bool = False

Expand Down
2 changes: 2 additions & 0 deletions mapillary_tools/process_geotag_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def process_geotag_properties(
interpolation_offset_time: float = 0.0,
num_processes: int | None = None,
skip_subfolders=False,
# True from the process command, unless --no_file_time_as_capture_time;
# video_process leaves it False
use_file_time_as_capture_time: bool = False,
) -> list[types.MetadataOrError]:
import_paths = _normalize_import_paths(import_path)
Expand Down
8 changes: 4 additions & 4 deletions mapillary_tools/process_sequence_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ def _check_sequences_by_limits(
if file_timed:
message += (
f". The capture times of {file_timed} of the {len(sequence)} "
"images are their file times (--use_file_time_as_capture_time), "
"which are usually when the files were exported, downloaded or "
"copied, not when the images were taken. Write the real capture "
"times into the images instead"
"images are their file times, as they have no capture time in "
"their metadata. File times are usually when the files were "
"exported, downloaded or copied, not when the images were "
"taken. Write the real capture times into the images instead"
)
error = exceptions.MapillaryCaptureSpeedTooFastError(message)
LOG.error(f"{_sequence_name(sequence)}: {error}")
Expand Down
19 changes: 10 additions & 9 deletions tests/integration/test_process_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def _write_image_without_capture_time(image_path: Path) -> Path:
return image_path


def test_process_fails_an_image_without_capture_time_by_default(
def test_process_fails_an_image_without_capture_time_when_told_to(
tmpdir: py.path.local,
):
root = Path(str(tmpdir))
Expand All @@ -375,7 +375,11 @@ def test_process_fails_an_image_without_capture_time_by_default(
# Without ExifTool installed, the default exiftool_runtime source, tried
# last, would report that instead
descs, report = _run_process_with_report(
[image_path.parent], root, "--geotag_source", "native"
[image_path.parent],
root,
"--geotag_source",
"native",
"--no_file_time_as_capture_time",
)

[desc] = descs
Expand All @@ -384,26 +388,23 @@ def test_process_fails_an_image_without_capture_time_by_default(
"Unable to extract timestamp from the image: it has a GPS position but no "
"capture time."
)
assert "--use_file_time_as_capture_time" in desc["error"]["message"]
assert report["warnings"] == []


def test_process_report_warns_of_an_image_given_its_file_time(
tmpdir: py.path.local,
):
"""
With --use_file_time_as_capture_time, an image with a GPS position but no
capture time gets the earlier of its file times as its capture time, and a
warning in the report
By default, an image with a GPS position but no capture time gets the
earlier of its file times as its capture time, and a warning in the report
"""
root = Path(str(tmpdir))
image_path = _write_image_without_capture_time(
root / "images" / "no_capture_time.jpg"
)

descs, report = _run_process_with_report(
[image_path.parent], root, "--use_file_time_as_capture_time"
)
# The default geotag sources, with or without ExifTool installed
descs, report = _run_process_with_report([image_path.parent], root)

[desc] = descs
assert "error" not in desc
Expand Down
37 changes: 32 additions & 5 deletions tests/unit/test_command_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# LICENSE file in the root directory of this source tree.

import argparse
import inspect

import pytest
from mapillary_tools.commands import (
Expand All @@ -12,24 +13,50 @@
video_process,
video_process_and_upload,
)
from mapillary_tools.process_geotag_properties import process_geotag_properties


def _option_strings(command) -> set:
def _parser(command) -> argparse.ArgumentParser:
# As the command line builds it
parser = argparse.ArgumentParser(conflict_handler="resolve")
command.Command().add_basic_arguments(parser)
return {option for action in parser._actions for option in action.option_strings}
return parser


def _option_strings(command) -> set:
return {
option
for action in _parser(command)._actions
for option in action.option_strings
}


def _use_file_time(command, *args: str) -> bool:
"""
What process_geotag_properties gets for use_file_time_as_capture_time from
the command line
"""
# The import paths are added by __main__
vars_args = vars(_parser(command).parse_args(list(args)))
return vars_args.get(
"use_file_time_as_capture_time",
inspect.signature(process_geotag_properties)
.parameters["use_file_time_as_capture_time"]
.default,
)


@pytest.mark.parametrize("command", [process, process_and_upload])
def test_process_takes_the_file_time_option(command):
assert "--use_file_time_as_capture_time" in _option_strings(command)
def test_process_uses_the_file_time_unless_told_not_to(command):
assert _use_file_time(command)
assert not _use_file_time(command, "--no_file_time_as_capture_time")


@pytest.mark.parametrize("command", [video_process, video_process_and_upload])
def test_video_process_does_not(command):
"""The frames get their times from the video"""
options = _option_strings(command)
assert "--use_file_time_as_capture_time" not in options
assert "--no_file_time_as_capture_time" not in options
assert not _use_file_time(command)
# The other process options are still there
assert "--geotag_source" in options
8 changes: 4 additions & 4 deletions tests/unit/test_geotag_file_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

"""
An image with a GPS position but no capture time in its metadata gets its file
time from geotag/factory.process, if asked for (--use_file_time_as_capture_time)
and no source reads a capture time for it
time from geotag/factory.process, unless told not to
(--no_file_time_as_capture_time), if no source reads a capture time for it
"""

from __future__ import annotations
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_an_image_without_gps_still_fails(tmp_path: Path):
assert str(metadata.error) == "Unable to extract timestamp from the image"


def test_the_image_fails_unless_the_file_time_is_asked_for(tmp_path: Path, caplog):
def test_the_image_fails_without_the_file_time(tmp_path: Path, caplog):
image = _write_image(tmp_path / "image.jpg")
xml_path = _write_xml(tmp_path / "image.xml", image, None)

Expand All @@ -207,5 +207,5 @@ def test_the_image_fails_unless_the_file_time_is_asked_for(tmp_path: Path, caplo
"Unable to extract timestamp from the image: it has a GPS position but no "
"capture time."
)
assert "--use_file_time_as_capture_time" in str(metadata.error)
assert "file time" not in str(metadata.error)
assert _file_time_warnings(caplog) == []
14 changes: 7 additions & 7 deletions tests/unit/test_image_exif_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,15 @@ def _gps_element(**tags: str) -> ET.Element:
NO_CAPTURE_TIME = (
"Unable to extract timestamp from the image: it has a GPS position but no "
"capture time. Write the capture time into the image (with ExifTool, for "
"example), or use --use_file_time_as_capture_time if the time of the file is "
"when the image was taken"
"example)"
)


class TestNoCaptureTimeByDefault:
class TestNoCaptureTimeWithoutFileTime:
"""
An image with a GPS position but no capture time fails, unless the file
time is asked for: the error says how to fix it
Without use_file_time (--no_file_time_as_capture_time, or video_process),
an image with a GPS position but no capture time fails: the error says how
to fix it
"""

def test_exif(self, tmp_path: Path):
Expand All @@ -530,7 +530,7 @@ def test_exiftool(self, tmp_path: Path):

assert str(info.value) == NO_CAPTURE_TIME

def test_an_image_on_a_track_is_not_told_to_use_the_file_time(self, tmp_path: Path):
def test_an_image_on_a_track_is_not_said_to_have_gps(self, tmp_path: Path):
image = _write_image_with_dates(tmp_path / "image.jpg", {})

with pytest.raises(exceptions.MapillaryGeoTaggingError) as info:
Expand All @@ -541,7 +541,7 @@ def test_an_image_on_a_track_is_not_told_to_use_the_file_time(self, tmp_path: Pa

class TestFileTimeForImagesWithoutCaptureTime:
"""
Asked for (--use_file_time_as_capture_time), an image with a GPS position
With use_file_time (process, by default), an image with a GPS position
but no capture time in its metadata gets the earlier of its file
modification and creation times, with a warning, but not where the capture
time places it on a track
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_sequence_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,8 +1380,8 @@ def test_capture_speed_error_says_when_times_are_file_times(
tmpdir: py.path.local, file_timed: int
):
"""
Images given their file times (--use_file_time_as_capture_time) that are
too fast for their positions: the error says where the times came from,
Images given their file times, for want of a capture time, that are too
fast for their positions: the error says where the times came from,
and only then
"""
sequence = [
Expand All @@ -1406,10 +1406,10 @@ def test_capture_speed_error_says_when_times_are_file_times(
if file_timed:
assert str(error).endswith(
f"km/h. The capture times of {file_timed} of the 2 images are their "
"file times (--use_file_time_as_capture_time), which are usually "
"when the files were exported, downloaded or copied, not when the "
"images were taken. Write the real capture times into the images "
"instead"
"file times, as they have no capture time in their metadata. File "
"times are usually when the files were exported, downloaded or "
"copied, not when the images were taken. Write the real capture "
"times into the images instead"
)
else:
assert str(error).endswith(" km/h")
Loading