Made output path configurable on cli.

Make SIFACTOR configurable on cli.
Output path, filename now dynamic.
This commit is contained in:
Marcus Scholz 2020-03-01 23:21:52 +01:00
parent 16bb735b29
commit f32fa7adba

View File

@ -6,13 +6,14 @@ DateTimeOriginal from Exif tag to DateTime in a csv log
of a GeigerMuellerCounter."""
from datetime import datetime
import os
import csv
import argparse
from PIL import Image
import piexif
import piexif.helper
# Constants for GQ geiger counters
# SIFACTOR for GQ geiger counters
# 300 series: 0.0065 µSv/h / CPM
# 320 series: 0.0065 µSv/h / CPM
@ -21,15 +22,18 @@ import piexif.helper
# 600 series: 0.0065 µSv/h / CPM
# 600+ series: 0.002637 µSv/h / CPM
SIFACTOR = 0.0065
parser = argparse.ArgumentParser(description='''A tool that writes
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='''A tool that writes
radiation levels (and optionally geocoordinates) to image files
and extracts the infos from external sources.''')
parser.add_argument('-si', '--sifactor', type=float, default=0.0065,
help='Factor to multiply recorded CPM with.')
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.')
parser.add_argument('-o', '--outdir', type=str, default='.',
help='Directory to output processed photos')
args = parser.parse_args()
@ -50,7 +54,7 @@ with open(args.csv, "r") as f:
csvisotime = datetime.fromisoformat(csvrawtime)
if csvisotime == picisotime:
rad = round(float(csvrawcpm) * SIFACTOR, 2)
rad = round(float(csvrawcpm) * args.sifactor, 2)
print("Radiation at time of photo: ", rad, "µS/h")
# convert str to exif compatible string
@ -61,5 +65,6 @@ with open(args.csv, "r") as f:
# 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)
outfile = os.path.join(args.outdir, photo)
im.save(outfile, exif=exif_bytes)
break