PlantCam file ordening script

I recently got a copy of the data as retrieved by my PlantCam installed in Yangambi, DR Congo. Before processing could proceed I had to rename all files from the standard Wingscapes PlantCam format to a format compatible with the PhenoCam GUI.

I wrote a little script in bash that does just this job. If run within a directory of PlantCam images it will use the exif data to create the appropriate filenames and file structures as required by the Phenocam GUI. You find the code below. The code depends on the CLI exif program and takes one parameter, mainly the site name.


# 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.
# written by Koen Hufkens, 24/08/2013

# get a list of all wingscape files
files=`ls *.JPG`

# pick your own sitename

for i in $files;
	# 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


# 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;

echo $i

# if the year directory does not exist, create it
if [ ! -d "./$i" ]; then
mkdir ./$i

	for j in $months;

		# if the month directory does not exits, create it
		if [ ! -d "./$j" ]; then
		mkdir ./$i/$j

		#files_to_move=`ls *_${i}_${j}_*.jpg`
		mv *_${i}_${j}_*.jpg ./$i/$j



© 2018. All rights reserved.

Powered by Hydejack v7.5.1