Added a working match class that returns best match for radiation and position.
Still ugly and a lot of debug output. Also not finished.
This commit is contained in:
parent
cf4007c909
commit
952f2726ba
38
functions.py
38
functions.py
|
@ -11,7 +11,7 @@ import pyexiv2
|
||||||
|
|
||||||
class Radiation:
|
class Radiation:
|
||||||
'''
|
'''
|
||||||
Reiceives Values vom CSV file and creates a list of the relevant data
|
Reiceives values vom CSV file and creates a list of the relevant data
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
timestamp: Date/time string from CSV as string
|
timestamp: Date/time string from CSV as string
|
||||||
|
@ -101,27 +101,24 @@ class Match:
|
||||||
position_list: list of timestamp / position / elevation values
|
position_list: list of timestamp / position / elevation values
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
timestamp: as datetime object
|
minimal timedelta: as timedelta object
|
||||||
radiation: in µS/h as string
|
best matching valuerow
|
||||||
latitude: in decimal format as float
|
|
||||||
longitude: in decimal format as float
|
|
||||||
elevation: in meters as float
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, photo_time, radiation_list, position_list):
|
def __init__(self, photo_time, radiation_list, position_list):
|
||||||
# self.radiation = self._find_match(photo_time, radiation_list)
|
self.radiation = self._find_radiation_match(photo_time, radiation_list)
|
||||||
self.position = self._find_match(photo_time, position_list)
|
self.position = self._find_position_match(photo_time, position_list)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _find_match(self, photo_time, list):
|
def _find_radiation_match(self, photo_time, list):
|
||||||
valuelist = []
|
valuelist = []
|
||||||
for row in list:
|
for row in list:
|
||||||
# Define timedelta and define timedelta datetime object.
|
# Define timedelta and define timedelta datetime object.
|
||||||
delta = timedelta(seconds=60)
|
delta = timedelta(seconds=60)
|
||||||
time_delta = abs(row.timestamp - photo_time)
|
if row.timestamp:
|
||||||
# time_delta = abs(row[0] - photo_time)
|
time_delta = abs(row.timestamp - photo_time)
|
||||||
# datetime objects should match with 1 minute precision.
|
# datetime objects should match with 1 minute precision.
|
||||||
if time_delta < delta:
|
if time_delta < delta:
|
||||||
element = (time_delta, row)
|
element = (time_delta, row)
|
||||||
|
@ -129,6 +126,25 @@ class Match:
|
||||||
# Return the list item with the lowest timedelta in column 0.
|
# Return the list item with the lowest timedelta in column 0.
|
||||||
# Column 2 contains the source objects untouched.
|
# Column 2 contains the source objects untouched.
|
||||||
if valuelist:
|
if valuelist:
|
||||||
|
print(min(valuelist, key=lambda x: x[0]))
|
||||||
|
return min(valuelist, key=lambda x: x[0])
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _find_position_match(self, photo_time, list):
|
||||||
|
valuelist = []
|
||||||
|
for row in list:
|
||||||
|
# Define timedelta and define timedelta datetime object.
|
||||||
|
delta = timedelta(seconds=60)
|
||||||
|
if row[0]:
|
||||||
|
time_delta = abs(row[0] - photo_time)
|
||||||
|
# datetime objects should match with 1 minute precision.
|
||||||
|
if time_delta < delta:
|
||||||
|
element = (time_delta, row)
|
||||||
|
valuelist.append(element)
|
||||||
|
# Return the list item with the lowest timedelta in column 0.
|
||||||
|
# Column 2 contains the source objects untouched.
|
||||||
|
if valuelist:
|
||||||
|
print(min(valuelist, key=lambda x: x[0]))
|
||||||
return min(valuelist, key=lambda x: x[0])
|
return min(valuelist, key=lambda x: x[0])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
24
rad_tag.py
24
rad_tag.py
|
@ -10,7 +10,7 @@ import csv
|
||||||
import argparse
|
import argparse
|
||||||
import pytz
|
import pytz
|
||||||
import gpxpy
|
import gpxpy
|
||||||
from functions import Radiation, Photo, Exif, Match
|
from functions import Radiation, Photo, Match, Exif
|
||||||
|
|
||||||
# SIFACTOR for GQ Geiger counters
|
# SIFACTOR for GQ Geiger counters
|
||||||
|
|
||||||
|
@ -60,21 +60,22 @@ with open(args.csv, "r") as f:
|
||||||
for _, csv_raw_time, csv_raw_cpm, _ in csv:
|
for _, csv_raw_time, csv_raw_cpm, _ in csv:
|
||||||
radiation = Radiation(csv_raw_time, csv_raw_cpm, local_timezone, args.sifactor)
|
radiation = Radiation(csv_raw_time, csv_raw_cpm, local_timezone, args.sifactor)
|
||||||
radiation_list.append(radiation)
|
radiation_list.append(radiation)
|
||||||
|
|
||||||
# close CSV file
|
# close CSV file
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Import GPX track(s)
|
# Import GPX track(s)print
|
||||||
if args.gpx is not None:
|
if args.gpx is not None:
|
||||||
gpx_file = open(args.gpx, 'r')
|
gpx_file = open(args.gpx, 'r')
|
||||||
gpx_reader = gpxpy.parse(gpx_file)
|
gpx_reader = gpxpy.parse(gpx_file)
|
||||||
|
#for waypoint in gpx_reader.waypoints:
|
||||||
for waypoint in gpx_reader.waypoints:
|
for track in gpx_reader.tracks:
|
||||||
for track in gpx_reader.tracks:
|
for segment in track.segments:
|
||||||
for segment in track.segments:
|
for point in segment.points:
|
||||||
for point in segment.points:
|
point_aware_time = point.time.astimezone(local_timezone)
|
||||||
position = [point.time, point.latitude, point.longitude, point.elevation]
|
#point_aware_time = point_naive_time.astimezone(local_timezone)
|
||||||
position_list.append(position)
|
position = (point_aware_time, point.latitude, point.longitude,
|
||||||
|
point.elevation, local_timezone)
|
||||||
|
position_list.append(position)
|
||||||
|
|
||||||
# Inform the user about what is going to happen
|
# Inform the user about what is going to happen
|
||||||
if args.dry is True:
|
if args.dry is True:
|
||||||
|
@ -92,6 +93,7 @@ for src_photo in args.photos:
|
||||||
# Here the matching magic has to happen
|
# Here the matching magic has to happen
|
||||||
|
|
||||||
match = Match(photo.get_date, radiation_list, position_list)
|
match = Match(photo.get_date, radiation_list, position_list)
|
||||||
|
#print(match)
|
||||||
|
|
||||||
latitude = 51.0234024
|
latitude = 51.0234024
|
||||||
longitude = 7.248347
|
longitude = 7.248347
|
||||||
|
@ -100,7 +102,7 @@ for src_photo in args.photos:
|
||||||
|
|
||||||
# Write exif data
|
# Write exif data
|
||||||
exif_tags = Exif(photo.get_target_photo, args.dry, radiation, latitude, longitude, elevation)
|
exif_tags = Exif(photo.get_target_photo, args.dry, radiation, latitude, longitude, elevation)
|
||||||
print(exif_tags)
|
#print(exif_tags)
|
||||||
|
|
||||||
# Print table header
|
# Print table header
|
||||||
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment'))
|
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment'))
|
Loading…
Reference in New Issue