From f0f6363d8d18335507df0ff896ba5467d6e6354e Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Sun, 1 Mar 2020 19:16:44 +0100 Subject: [PATCH] First (somewhat) working prototype with static image --- exif_rad.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/exif_rad.py b/exif_rad.py index 7d31cf5..ccb78f2 100755 --- a/exif_rad.py +++ b/exif_rad.py @@ -6,7 +6,6 @@ DateTimeOriginal from Exif tag to DateTime in a csv log of a GeigerMuellerCounter.""" from datetime import datetime -# import math from PIL import Image import piexif import piexif.helper @@ -25,33 +24,34 @@ SIFACTOR = 0.0065 # Temp constants RAD = "0,15" -# Import GeigerCounter data -with open("testdata/TKRZ.hisdb.his", "r") as f: - for line in f: - if line[0] != '#': - columns = line.split(',') - csvrawtime = columns[1].lstrip() - csvrawcpm = columns[2].lstrip() - csvrawrad = round(float(csvrawcpm) * SIFACTOR, 2) - csvisotime = datetime.fromisoformat(csvrawtime) - # Print with 2 digits after dot and unit of measurement - print(csvisotime, csvrawrad, "µS/h") - # Load Image and EXIF data -im = Image.open("testdata/test.jpg") +im = Image.open("testdata/DSC_0183.JPG") exif_dict = piexif.load(im.info["exif"]) picrawtime = exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode('ASCII') picisotime = datetime.strptime(picrawtime, "%Y:%m:%d %H:%M:%S") -print(picisotime) +print("Timestamp of image: ", picisotime) -# convert str to exif compatible string -new_comment = "Radiation ☢ " + 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: + for line in f: + if line[0] != '#': + columns = line.split(',') + csvrawtime = columns[1].lstrip() + csvrawcpm = columns[2].lstrip() + csvisotime = datetime.fromisoformat(csvrawtime) + + if csvisotime == picisotime: + rad = round(float(csvrawcpm) * SIFACTOR, 2) + print("Radiation at time of photo: ", rad, "µS/h") -# compile and write tags -print("Going to write comment: " + new_comment) -exif_bytes = piexif.dump(exif_dict) -#im.save("test.jpg", exif=exif_bytes) + # 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)