Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (58 sloc) 4.94 KB
# this script extracts timestamps from files and writes them into the dataframe.
# it also finesses those timestamps into time-per-revolution, through what i'm
# sure will be hilariously ugly code.
setwd("/home/josh/school/thesis")
#matResponse <- read.csv("matResponse.csv", na.strings="NA")
#matResponse <- read.csv("offspringHygr.csv", na.strings="")
matResponse <- read.csv("fullSticks.csv", na.strings="")
#hdPath <- "/media/8df4de9b-c727-4b6f-8db3-77ae2b270354/" #the trailing / is important. i don't check for it.
hdPath <- "/media/fbcd84c7-9503-4120-b264-8e85f5c916bc/thesisphotos/"
f.cut <- "cut -c 61-"
#define a function for system() so I can pass along intern=TRUE in apply()
f.sys <- function(x) { system(x, intern=TRUE)}
#this builds the commands to be run by the shell for each rotation set
commandsExif0 <- paste("exiv2 pr -g Exif.Image.DateTime ", hdPath, matResponse$directory, "/", matResponse$rot0file, " | ", f.cut, sep="")
commandsExif1 <- paste("exiv2 pr -g Exif.Image.DateTime ", hdPath, matResponse$directory[complete.cases(matResponse$rot1file)], "/", matResponse$rot1file[complete.cases(matResponse$rot1file)], " | ", f.cut, sep="")
#commandsExif2 <- paste("exiv2 pr -g Exif.Image.DateTime ", hdPath, matResponse$directory[complete.cases(matResponse$rot2file)], "/", matResponse$rot2file[complete.cases(matResponse$rot2file)], " | ", f.cut, sep="")
#commandsExif3 <- paste("exiv2 pr -g Exif.Image.DateTime ", hdPath, matResponse$directory[complete.cases(matResponse$rot3file)], "/", matResponse$rot3file[complete.cases(matResponse$rot3file)], " | ", f.cut, sep="")
#actually pull out the data. subsetception in here.
matResponse$timestamp0 <- apply(as.matrix(commandsExif0), MARGIN=1,FUN=f.sys)
matResponse$timestamp1[complete.cases(matResponse$rot1file)] <- apply(as.matrix(commandsExif1), MARGIN=1,FUN=f.sys)
matResponse$timestamp2[complete.cases(matResponse$rot2file)] <- apply(as.matrix(commandsExif2), MARGIN=1,FUN=f.sys)
matResponse$timestamp3[complete.cases(matResponse$rot3file)] <- apply(as.matrix(commandsExif3), MARGIN=1,FUN=f.sys)
#write.csv(matResponse, file="matResponse.csv") #update dataset
#convert these to POSIXlt timestamps
matResponse$dts0 <- strptime(matResponse$timestamp0, format="%Y:%m:%d %H:%M:%S")
matResponse$dts1 <- strptime(matResponse$timestamp1, format="%Y:%m:%d %H:%M:%S")
matResponse$dts2 <- strptime(matResponse$timestamp2, format="%Y:%m:%d %H:%M:%S")
matResponse$dts3 <- strptime(matResponse$timestamp3, format="%Y:%m:%d %H:%M:%S")
matResponse$spin1 <- difftime(matResponse$dts1, matResponse$dts0, units="secs")
matResponse$spin2 <- difftime(matResponse$dts2, matResponse$dts1, units="secs")
matResponse$spin3 <- difftime(matResponse$dts3, matResponse$dts2, units="secs")
#write.csv(matResponse, "offspringHygr.csv") i didn't change the variable names.
#write.csv(matResponse, "fullSticks.csv") #when i ran it as fullsticks
###############################################################################
# deal with the seeds from wide distribution, photos taken Jan 3, 2012
distHygr <- read.csv("distributionHygrSticks.csv", na.strings="NA")
#distHygr <- read.csv("distributionHygrSticks-2.csv", na.strings="NA")
commandsExif0 <- paste("exiv2 pr -g Exif.Image.DateTime ", hdPath, distHygr$directory, "/",
distHygr$rot0file, " | ", f.cut, sep="")
commandsExif1 <- paste("exiv2 pr -g Exif.Image.DateTime ", hdPath, distHygr$directory[complete.cases(distHygr$rot1file)], "/",
distHygr$rot1file[complete.cases(distHygr$rot1file)], " | ", f.cut, sep="")
commandsExif2 <- paste("exiv2 pr -g Exif.Image.DateTime ", hdPath, distHygr$directory[complete.cases(distHygr$rot2file)], "/",
distHygr$rot2file[complete.cases(distHygr$rot2file)], " | ", f.cut, sep="")
commandsExif3 <- paste("exiv2 pr -g Exif.Image.DateTime ", hdPath, distHygr$directory[complete.cases(distHygr$rot3file)], "/",
distHygr$rot3file[complete.cases(distHygr$rot3file)], " | ", f.cut, sep="")
distHygr$timestamp0 <- apply(as.matrix(commandsExif0), MARGIN=1,FUN=f.sys)
distHygr$timestamp1[complete.cases(distHygr$rot1file)] <- apply(as.matrix(commandsExif1), MARGIN=1,FUN=f.sys)
distHygr$timestamp2[complete.cases(distHygr$rot2file)] <- apply(as.matrix(commandsExif2), MARGIN=1,FUN=f.sys)
distHygr$timestamp3[complete.cases(distHygr$rot3file)] <- apply(as.matrix(commandsExif3), MARGIN=1,FUN=f.sys)
distHygr$dts0 <- strptime(distHygr$timestamp0, format="%Y:%m:%d %H:%M:%S")
distHygr$dts1 <- strptime(distHygr$timestamp1, format="%Y:%m:%d %H:%M:%S")
distHygr$dts2 <- strptime(distHygr$timestamp2, format="%Y:%m:%d %H:%M:%S")
distHygr$dts3 <- strptime(distHygr$timestamp3, format="%Y:%m:%d %H:%M:%S")
distHygr$spin1 <- difftime(distHygr$dts1, distHygr$dts0, units="secs")
distHygr$spin2 <- difftime(distHygr$dts2, distHygr$dts1, units="secs")
distHygr$spin3 <- difftime(distHygr$dts3, distHygr$dts2, units="secs")
distHygr <- distHygr[distHygr$site!="blank",]
write.csv(distHygr, file="distributionHygrSticks-2.csv")
You can’t perform that action at this time.