forked from gtatters/Thermimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflirsettings.R
74 lines (61 loc) · 2.63 KB
/
flirsettings.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#' @export
#'
flirsettings<-function(imagefile, exiftoolpath="installed", camvals=NULL)
{
# source: http://timelyportfolio.github.io/rCharts_catcorrjs/exif/
# see also here for converting thermal image values
# http://u88.n24.queensu.ca/exiftool/forum/index.php?topic=4898.45
# accessing exiftool from system command line
# Decipher Camera Meta Data information
# Need to have exiftool installed in your OS's system folder or equivalent
# http://www.sno.phy.queensu.ca/~phil/exiftool/
if(exiftoolpath=="installed"){
exiftoolpath<-""
}
if(is.null(camvals)) {
camvals<-"-flir -*Emissivity -*Original -*Date -*Planck* -*AtmosphericTrans* -*Distance -*Temperature* -*Transmission -*Humidity -*Height -*Width -*Model* -*Median -*Range -*Raw*"
}
syscommand<-paste0(exiftoolpath, "exiftool")
info<-system2(syscommand, args=paste0(shQuote(imagefile), " ", camvals), stdout=T)
info.df<-utils::read.fwf(textConnection(info), widths=c(32,1,1,60), stringsAsFactors=FALSE, header=FALSE, fill=FALSE)
info.df<-info.df[,-c(2,3)]
whichdates<-grep("Date", info.df[,1])
# these variables are date/time variables
datevariables<-gsub(" ", "", info.df[whichdates,1])
datevariables<-gsub("/", "", datevariables)
datevalues<-info.df[whichdates,2]
tz<-substr(datevalues, nchar(datevalues)-5,nchar(datevalues))
datevalues<-as.character(gsub("[^0-9: .-]","", datevalues))
notdates<-!1:nrow(info.df) %in% grep("Date", info.df[,1])
variables<-gsub(" ", "", info.df[notdates,1])
variables<-gsub("/", "", variables)
values<-as.character(gsub("[^0-9: .-]","", info.df[notdates,2]))
values[which(info.df[notdates,2]=="TIFF")]<-"TIFF"
values[which(info.df[notdates,2]=="PNG")]<-"PNG"
values<-gsub("[[:space:]]", "", values)
# removes all spaces from non-date values
suffixes<-gsub("([0-9.])","",info.df[notdates,2])
dates<-gsub(":", "-", substr(datevalues, 1, 10), fixed=TRUE)
times<-substr(datevalues, 12, 19)
no.tz<-grep("[:]", substr(tz,1,1))
# which timezones were blank
tz<-gsub(":", "", tz, fixed=TRUE)
# remove colons from tz
tz[no.tz]<-"+0000"
# when in doubt, force the times without TZ to "+00:00". not sure how to fix this
#tz<-paste0(" ", tz)
datechar<-paste0(dates, " ", times, " ", tz)
datevalues<-strptime(datechar, format="%Y-%m-%d %H:%M:%S %z")
df<-as.list(values)
names(df)<-variables
suppressWarnings(
df[!is.na(as.numeric(values))]<-as.numeric(df[!is.na(as.numeric(values))])
)
df2<-data.frame(datevalues)
df2<-as.list(t(df2))
names(df2)<-datevariables
settings<-list(df, df2)
names(settings)<-c("Info", "Dates")
rm(exiftoolpath)
return(settings)
}