Added command line paremeters
Added basic args, help
This commit is contained in:
parent
6c4626ed50
commit
849d08060f
62
exif_rad.py
62
exif_rad.py
@ -7,6 +7,7 @@ of a GeigerMuellerCounter."""
|
||||
|
||||
from datetime import datetime
|
||||
import csv
|
||||
import argparse
|
||||
from PIL import Image
|
||||
import piexif
|
||||
import piexif.helper
|
||||
@ -22,36 +23,43 @@ import piexif.helper
|
||||
|
||||
SIFACTOR = 0.0065
|
||||
|
||||
# Temp constants
|
||||
RAD = "0,15"
|
||||
parser = argparse.ArgumentParser(description='''A tool that writes
|
||||
radiation levels (and optionally geocoordinates) to image files
|
||||
and extracts the infos from external sources.''')
|
||||
parser.add_argument('csv', metavar='CSV', type=str,
|
||||
help='Geiger counter history file in CSV format.')
|
||||
parser.add_argument('photos', metavar='Photo', type=str, nargs='+',
|
||||
help='One or multiple photo image files to process.')
|
||||
|
||||
# Load Image and EXIF data
|
||||
im = Image.open("testdata/DSC_0183.JPG")
|
||||
exif_dict = piexif.load(im.info["exif"])
|
||||
args = parser.parse_args()
|
||||
|
||||
picrawtime = exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode('ASCII')
|
||||
picisotime = datetime.strptime(picrawtime, "%Y:%m:%d %H:%M:%S")
|
||||
for photo in args.photos:
|
||||
# Load Image and EXIF data
|
||||
im = Image.open(photo)
|
||||
exif_dict = piexif.load(im.info["exif"])
|
||||
|
||||
print("Timestamp of image: ", picisotime)
|
||||
picrawtime = exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode('ASCII')
|
||||
picisotime = datetime.strptime(picrawtime, "%Y:%m:%d %H:%M:%S")
|
||||
|
||||
# Import GeigerCounter log
|
||||
with open("testdata/test.hisdb.his", "r") as f:
|
||||
csvreader = csv.reader(filter(lambda row: row[0]!='#', f), delimiter=',', skipinitialspace=True)
|
||||
for _, csvrawtime, csvrawcpm, _ in csvreader:
|
||||
print(csvrawtime, csvrawcpm)
|
||||
csvisotime = datetime.fromisoformat(csvrawtime)
|
||||
|
||||
if csvisotime == picisotime:
|
||||
rad = round(float(csvrawcpm) * SIFACTOR, 2)
|
||||
print("Radiation at time of photo: ", rad, "µS/h")
|
||||
print("Timestamp of image: ", picisotime)
|
||||
|
||||
# convert str to exif compatible string
|
||||
new_comment = "Radiation ☢ " + str(rad) + " µS/h"
|
||||
user_comment = piexif.helper.UserComment.dump(new_comment, encoding="unicode")
|
||||
exif_dict["Exif"][piexif.ExifIFD.UserComment] = user_comment
|
||||
# Import GeigerCounter log
|
||||
with open("testdata/test.hisdb.his", "r") as f:
|
||||
csvreader = csv.reader(filter(lambda row: row[0]!='#', f), delimiter=',', skipinitialspace=True)
|
||||
for _, csvrawtime, csvrawcpm, _ in csvreader:
|
||||
csvisotime = datetime.fromisoformat(csvrawtime)
|
||||
|
||||
# compile and write tags
|
||||
print("Going to write comment: " + new_comment)
|
||||
exif_bytes = piexif.dump(exif_dict)
|
||||
im.save("testdata/test.jpg", exif=exif_bytes)
|
||||
break
|
||||
if csvisotime == picisotime:
|
||||
rad = round(float(csvrawcpm) * SIFACTOR, 2)
|
||||
print("Radiation at time of photo: ", rad, "µS/h")
|
||||
|
||||
# convert str to exif compatible string
|
||||
new_comment = "Radiation ☢ " + str(rad) + " µS/h"
|
||||
user_comment = piexif.helper.UserComment.dump(new_comment, encoding="unicode")
|
||||
exif_dict["Exif"][piexif.ExifIFD.UserComment] = user_comment
|
||||
|
||||
# compile and write tags
|
||||
print("Going to write comment: " + new_comment)
|
||||
exif_bytes = piexif.dump(exif_dict)
|
||||
im.save("testdata/test.jpg", exif=exif_bytes)
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user