FANDOM


CodeEdit

import EXIF #EXIF.py
from datetime import datetime
from time import mktime
import csv
import sys
import os

"""
This script will take the photos from a high altitude balloon launch tracked via APRS and rename the filenames
according to the approximate altitude they were taken at.

It will assign the altitude of the last packet received before the picture to each picture. Ideally it would
make a linear fit between the two data points around it. Thats for a later version.

Ideally this script would geotag the photos by modifing the EXIF tags. This way the photos could be uploaded to
services like Flikr or Picasa and their location would be shown on a map. I was unable to get EXIF editing working
in Python, so that didn't happen.

Balloon Picture Altitude v0.1
GPL v3 June 2012 Matt Skorina
"""

# The time in seconds that the clock on the photo is behind the aprs time.
# Not that that you need to convert timezones, if time is correct but in localtime (GMT-7) offeset = 25200
offset = 25200

# Directory to hold photos. Have backup because this script will modify them.
# The trailing backslash is needed.
photoDir = 'photos/'

# Path to the location of the aprs.fi export of the flight. Select a timeframe to only include packets from the launch. In CSV format.
aprsExport = "aprs-fi.csv"


# You shouldn't need to modify anything below this line.
##########################################################################

photos = os.listdir(photoDir)

print(photos)

for i in range(len(photos)):
    photo = photos[i]
    # Read each photo and dump EXIF tags.
    photoFile = open(photoDir + photo, 'rb')
    tags = EXIF.process_file(photoFile)
    photoFile.close()
    
    # Find time photo was taken, save it.
    for tag in tags.keys():
        if (tag == "EXIF DateTimeOriginal"):
            photoTime = str(tags[tag])
    
    # Convert time picture was taken to date format and epoch time.
    photoTime = datetime.strptime(photoTime, "%Y:%m:%d %H:%M:%S")
    photoEpoch = mktime(photoTime.timetuple())
    
    # Convert photo epoch time to line up with aprs.fi export.
    photoEpoch = photoEpoch + offset
    
    # Open aprs.fi export.
    aprsFile = open(aprsExport, 'rt')
    reader = csv.reader(aprsFile)
    
    for row in reader:
        if (row[0] != "time"): # Ignore csv header line.
            aprsTime = datetime.strptime(row[0], "%Y-%m-%d %H:%M:%S")
            aprsEpoch = mktime(aprsTime.timetuple())
            if ( aprsEpoch > photoEpoch ):
                altFeet = int(float(row[6]) * 3.2808399) # Convert altitude from meters to feet.
                break

    print(photo, altFeet)
    count = str(i + 1)
    os.rename(photoDir + photo, photoDir + "IMG_" + count + " (" + str(altFeet) + "ft).jpg")

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.