Created
April 14, 2017 18:39
-
-
Save khufkens/6529650e2bba6a504ac38242fd771e21 to your computer and use it in GitHub Desktop.
Renames Wingscape Plantcam files to the PhenoCam file format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# convert wingscape PlantCam files | |
# and moves the files into the desired file structure | |
# for easy processing with the PhenoCam GUI or toolkit | |
# | |
# NOTE: requires a running version of linux/Mac or cygwin | |
# with exif installed. | |
# | |
# USE: plant2phenocam.sh MYSITE | |
# (MYSITE is your site name) | |
# | |
# renamed and sorted files are easily processed | |
# using the PhenoCamGUI | |
# | |
# written by Koen Hufkens, 24/08/2013 | |
# get a list of all wingscape files | |
files=`ls *.JPG` | |
# pick your own sitename | |
sitename=$1 | |
for i in $files; | |
do | |
# extract date and time from exif data | |
date=`exif $i | grep "Date and Time" | head -n 1 | cut -d'|' -f2 | cut -d' ' -f1 | sed 's/:/_/g'` | |
time=`exif $i | grep "Date and Time" | head -n 1 | cut -d'|' -f2 | cut -d' ' -f2 | sed 's/://g'` | |
# construct the final filename and rename (with copy not move) | |
tmp=`echo "$sitename $date $time.jpg"` | |
filename=`echo $tmp | sed 's/ /_/g'` | |
cp $i $filename | |
done | |
# sort files into the correct data structure (a folder for each month) | |
years=`ls *.jpg | cut -d'_' -f2 | uniq` | |
months=`ls *.jpg | cut -d'_' -f3 | uniq` | |
for i in $years; | |
do | |
echo $i | |
# if the year directory does not exist, create it | |
if [ ! -d "./$i" ]; then | |
mkdir ./$i | |
fi | |
for j in $months; | |
do | |
# if the month directory does not exits, create it | |
if [ ! -d "./$j" ]; then | |
mkdir ./$i/$j | |
fi | |
#files_to_move=`ls *_${i}_${j}_*.jpg` | |
mv *_${i}_${j}_*.jpg ./$i/$j | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment