<commit_before>#!/usr/bin/python

import sys
import os
import shutil
import gpxpy
import datetime
import math
import time
import geo
import pyexiv2
from pyexiv2.utils import make_fraction
import json
import numpy as np


'''
(source: https://github.com/mapillary/mapillary_tools)


Script for geotagging images using a gpx file from an external GPS.
Intended as a lightweight tool.

!!! This version needs testing, please report issues.!!!

Uses the capture time in EXIF and looks up an interpolated lat, lon, bearing
for each image, and writes the values to the EXIF of the image.

You can supply a time offset in seconds if the GPS clock and camera clocks are not in sync.

Requires gpxpy, e.g. 'pip install gpxpy'

Requires pyexiv2, see install instructions at http://tilloy.net/dev/pyexiv2/
(or use your favorite installer, e.g. 'brew install pyexiv2').
'''

def utc_to_localtime(utc_time):
    utc_offset_timedelta = datetime.datetime.utcnow() - datetime.datetime.now()
    return utc_time - utc_offset_timedelta


def get_lat_lon_time(gpx_file):
    '''
    Read location and time stamps from a track in a GPX file.

    Returns a list of tuples (time, lat, lon, elevation).

    GPX stores time in UTC, assume your camera used the local
    timezone and convert accordingly.
    '''
    with open(gpx_file, 'r') as f:
        gpx = gpxpy.parse(f)

    points = []
    for track in gpx.tracks:
        for segment in track.segments:
            for point in segment.points:
                points.append( (utc_to_localtime(point.time), point.latitude, point.longitude, point.elevation) )
<commit_msg>geotag: add option to set gpx time format<commit_after>#!/usr/bin/python

import sys
import os
import shutil
import gpxpy
import datetime
import math
import time
import geo
import pyexiv2
from pyexiv2.utils import make_fraction
import json
import numpy as np


'''
(source: https://github.com/mapillary/mapillary_tools)


Script for geotagging images using a gpx file from an external GPS.
Intended as a lightweight tool.

!!! This version needs testing, please report issues.!!!

Uses the capture time in EXIF and looks up an interpolated lat, lon, bearing
for each image, and writes the values to the EXIF of the image.

You can supply a time offset in seconds if the GPS clock and camera clocks are not in sync.

Requires gpxpy, e.g. 'pip install gpxpy'

Requires pyexiv2, see install instructions at http://tilloy.net/dev/pyexiv2/
(or use your favorite installer, e.g. 'brew install pyexiv2').
'''

def utc_to_localtime(utc_time):
    utc_offset_timedelta = datetime.datetime.utcnow() - datetime.datetime.now()
    return utc_time - utc_offset_timedelta


def get_lat_lon_time(gpx_file, gpx_time='utc'):
    '''
    Read location and time stamps from a track in a GPX file.

    Returns a list of tuples (time, lat, lon, elevation).

    GPX stores time in UTC, assume your camera used the local
    timezone and convert accordingly.
    '''
    with open(gpx_file, 'r') as f:
        gpx = gpxpy.parse(f)

    points = []
    for track in gpx.tracks:
        for segment in track.segments:
            for point in segment.points:
                ptime = utc_to_localtime(point.time) if gpx_time=='utc' else point.time
                points.append( (ptime, point.latitude, point.longitude, point.elevation) )

{'fraction_non_alphanumeric': 0.07859078590785908, 'fraction_numerical': 0.0030111412225233363, 'mean_word_length': 3.4952638700947225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7628853', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1026, 'n_words': 402}