From 0fa87ab47a5e0b422a7887a069035a872f668307 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Sun, 1 Mar 2020 17:17:37 +0100 Subject: [PATCH] Initial commit Highly WIP does not yet do shit. --- .gitignore | 2 ++ exif_rad.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .gitignore create mode 100755 exif_rad.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e67672 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +testdata +usercomment.sh diff --git a/exif_rad.py b/exif_rad.py new file mode 100755 index 0000000..4804996 --- /dev/null +++ b/exif_rad.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +"""Iterates over a bunch of .jpg or .cr2 files and matches +DateTimeOriginal from Exif tag to DateTime in a csv log +of a GeigerMuellerCounter.""" + +from datetime import datetime +from PIL import Image +import math +import piexif +import piexif.helper + +# Constants +# 320 series: 0.0065 µSv/h / CPM +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") +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) + +# 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 + +# compile and write tags +print("Going to write comment: " + new_comment) +exif_bytes = piexif.dump(exif_dict) +#im.save("test.jpg", exif=exif_bytes)