Holy Moly! Such chaos. Hopefully it is fixed now.
This commit is contained in:
parent
9ac706075a
commit
f6a54a5855
55
functions.py
55
functions.py
|
@ -10,7 +10,20 @@ from fractions import Fraction
|
||||||
import pyexiv2
|
import pyexiv2
|
||||||
|
|
||||||
class Radiation:
|
class Radiation:
|
||||||
''' Handles CSV processing. '''
|
'''
|
||||||
|
Reiceives Values vom CSV file and creates a list of the relevant data
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
timestamp: Date/time string from CSV as string
|
||||||
|
radiation: Radiation from CSV in CP/M as float
|
||||||
|
local_timezone: timezone for timezone-unware CSV / Photo, if GPX is timezone aware
|
||||||
|
si_factor: CP/M to (µS/h) conversion factor - specific to GMC-tube
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
timestamp: timestamp of CSV value als datetime object
|
||||||
|
radiation: radiation in µS/h as str (for Exif comment, UTF-8)
|
||||||
|
'''
|
||||||
|
|
||||||
def __init__(self, timestamp, radiation, local_timezone, si_factor):
|
def __init__(self, timestamp, radiation, local_timezone, si_factor):
|
||||||
self.timestamp = self._time_conversion(timestamp, local_timezone)
|
self.timestamp = self._time_conversion(timestamp, local_timezone)
|
||||||
self.radiation = self._radiation_conversion(radiation, si_factor)
|
self.radiation = self._radiation_conversion(radiation, si_factor)
|
||||||
|
@ -30,7 +43,20 @@ class Radiation:
|
||||||
return radiation
|
return radiation
|
||||||
|
|
||||||
class Photo:
|
class Photo:
|
||||||
''' Reads and writes Exif metadata. '''
|
'''
|
||||||
|
Reads Exif metadata.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
photo: source photo ()
|
||||||
|
local_timezone: timezone for timezone-unware CSV / Photo, if GPX is timezone aware
|
||||||
|
dest_dir: destination directory where the photo is going to be copied to.
|
||||||
|
dry_run: whether to acutally write (True / False)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
self.get_date: timestamp of photo als datetime object
|
||||||
|
self.get_target_photo: full path to photo file to work on
|
||||||
|
'''
|
||||||
|
|
||||||
def __init__(self, photo, local_timezone, dest_dir, dry_run):
|
def __init__(self, photo, local_timezone, dest_dir, dry_run):
|
||||||
self.get_date = self._get_creation_date(photo, local_timezone)
|
self.get_date = self._get_creation_date(photo, local_timezone)
|
||||||
self.get_target_photo = self._copy_photo(photo, dest_dir, dry_run)
|
self.get_target_photo = self._copy_photo(photo, dest_dir, dry_run)
|
||||||
|
@ -57,7 +83,6 @@ class Photo:
|
||||||
# Load Exif data from photo
|
# Load Exif data from photo
|
||||||
metadata = pyexiv2.ImageMetadata(photo)
|
metadata = pyexiv2.ImageMetadata(photo)
|
||||||
metadata.read()
|
metadata.read()
|
||||||
print(metadata)
|
|
||||||
date = metadata['Exif.Photo.DateTimeOriginal']
|
date = metadata['Exif.Photo.DateTimeOriginal']
|
||||||
# date.value creates datetime object in pic_naive_time
|
# date.value creates datetime object in pic_naive_time
|
||||||
pic_naive_time = date.value
|
pic_naive_time = date.value
|
||||||
|
@ -66,7 +91,8 @@ class Photo:
|
||||||
return pic_aware_time
|
return pic_aware_time
|
||||||
|
|
||||||
class Exif:
|
class Exif:
|
||||||
''' Converts, compiles and writes Exif-Tags from given values.
|
'''
|
||||||
|
Converts, compiles and writes Exif-Tags from given arguemnts.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
photo: file name of photo to modify
|
photo: file name of photo to modify
|
||||||
|
@ -75,14 +101,18 @@ class Exif:
|
||||||
longitude: longitude as float
|
longitude: longitude as float
|
||||||
elevation: elevation as float
|
elevation: elevation as float
|
||||||
dry_run: whether to acutally write (True / False)
|
dry_run: whether to acutally write (True / False)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Latitude / Longitude in degrees
|
||||||
|
Exif-Comment that has been written (incl. radiation)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, photo, radiation, latitude, longitude, elevation, dry_run):
|
def __init__(self, photo, radiation, latitude, longitude, elevation, dry_run):
|
||||||
# self.get_degree = self._to_degree(value, loc)
|
self.write_exif = self._write_exif(photo, radiation, latitude,
|
||||||
self.write_exif = self._write_exif(photo, radiation, latitude, longitude, elevation, dry_run)
|
longitude, elevation, dry_run)
|
||||||
|
|
||||||
# def __repr__(self):
|
def __repr__(self):
|
||||||
# return 'Photo: %s Creation Date: %s' % (str(self.get_target_photo), str(self.get_date))
|
return 'Position: %s, %s: %s ' % self.write_exif
|
||||||
|
|
||||||
def _to_degree(self, value, loc):
|
def _to_degree(self, value, loc):
|
||||||
if value < 0:
|
if value < 0:
|
||||||
|
@ -106,9 +136,6 @@ class Exif:
|
||||||
latitude_degree = self._to_degree(latitude, ["S", "N"])
|
latitude_degree = self._to_degree(latitude, ["S", "N"])
|
||||||
longitude_degree = self._to_degree(longitude, ["W", "E"])
|
longitude_degree = self._to_degree(longitude, ["W", "E"])
|
||||||
|
|
||||||
print(latitude_degree)
|
|
||||||
print(longitude_degree)
|
|
||||||
|
|
||||||
# convert decimal coordinates into fractions required for pyexiv2
|
# convert decimal coordinates into fractions required for pyexiv2
|
||||||
exiv2_latitude = (Fraction(latitude_degree[0] * 60 + latitude_degree[1], 60),
|
exiv2_latitude = (Fraction(latitude_degree[0] * 60 + latitude_degree[1], 60),
|
||||||
Fraction(int(round(latitude_degree[2] * 100, 0)), 6000),
|
Fraction(int(round(latitude_degree[2] * 100, 0)), 6000),
|
||||||
|
@ -132,10 +159,8 @@ class Exif:
|
||||||
metadata['Exif.GPSInfo.GPSVersionID'] = '2 0 0 0'
|
metadata['Exif.GPSInfo.GPSVersionID'] = '2 0 0 0'
|
||||||
metadata['Exif.Photo.UserComment'] = new_comment
|
metadata['Exif.Photo.UserComment'] = new_comment
|
||||||
|
|
||||||
print(new_comment)
|
|
||||||
|
|
||||||
# Write Exif tags to file, if not in dry-run mode
|
# Write Exif tags to file, if not in dry-run mode
|
||||||
if dry_run is not True:
|
if dry_run is not True:
|
||||||
metadata.write()
|
metadata.write()
|
||||||
|
|
||||||
return new_comment
|
return latitude_degree, longitude_degree, new_comment
|
||||||
|
|
Loading…
Reference in New Issue