-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.R
More file actions
840 lines (749 loc) · 33.7 KB
/
server.R
File metadata and controls
840 lines (749 loc) · 33.7 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
#server.R
#For rHyperSpec_shinyapp
shinyServer(function(input, output) {
#### Reactive Functions ####
getCalTimestamp <- reactive({
#Read the first white panel calibration file, extract the timestamp
data <- read.table(as.character(input$calfiles[1,4]),skip = 2, nrow = 1,
fill = FALSE, header = FALSE,
stringsAsFactors = FALSE, strip.white = TRUE)
timestamp <- sub(as.vector(data[1,1]), pattern = "Time: ", replacement = "")
timestamp <- as.POSIXct(timestamp, format = "%m/%d/%Y %I:%M:%S %p")
return(timestamp)
})
getSoftwareVersion <- reactive({
#Read the first white panel calibration file, extract the software and version
line <- read.table(as.character(input$calfiles[1,4]),skip = 1, nrow = 1,
fill = FALSE, header = FALSE,
stringsAsFactors = FALSE, strip.white = TRUE)
software <- sub(as.vector(line[1,1]), pattern = "Remarks: SW=", replacement = "")
return(software)
})
getIntegrationTime <- reactive({
#Read the first white panel calibration file, extract the integration time
line <- read.table(as.character(input$calfiles[1,4]),skip = 7, nrow = 1,
fill = FALSE, header = FALSE,
stringsAsFactors = FALSE, strip.white = TRUE)
inttime <- sub(as.vector(line[1,1]), pattern = "Integration: ", replacement = "")
return(inttime)
})
getNumberScans <- reactive({
#Read the first white panel calibration file, extract the number of scans used per file
line <- read.table(as.character(input$calfiles[1,4]),skip = 8, nrow = 1,
fill = FALSE, header = FALSE,
stringsAsFactors = FALSE, strip.white = TRUE)
scans <- sub(as.vector(line[1,1]), pattern = "Number Scans: ", replacement = "")
return(scans)
})
getEventTimestamp <- reactive({
#Read the first event file, extract the timestamp
data <- read.table(as.character(input$eventfiles[1,4]),skip = 2, nrow = 1,
fill = FALSE, header = FALSE,
stringsAsFactors = FALSE, strip.white = TRUE)
timestamp <- sub(as.vector(data[1,1]), pattern = "Time: ", replacement = "")
timestamp <- as.POSIXct(timestamp, format = "%m/%d/%Y %I:%M:%S %p")
return(timestamp)
})
getDate <- reactive({
date <- substr(as.character(getCalTimestamp()), 1, 10)
return(date)
})
getDataFromFile <- function(filepath, chan){
#Extract the data from an .spu file. The resulting data frame has three
#columns: wavelength, radiance, and irradiance. If the user checks that the
#up fiber was attached to channel B, then switch the column names for
#radiance and irradiance.
data <- read.delim(filepath, fill = TRUE,
col.names = c("wavelength","radiance","irradiance"),
stringsAsFactors = FALSE, strip.white = TRUE)
data <- data[-grep(pattern = '[[:alpha:]]', x = data[,1]),]
data[,1] <- as.numeric(data[,1])
if(chan == "B"){names(data) <- c("wavelength","irradiance","radiance")}
return(data)
}
getLimitNR <- reactive({
limNR <- input$limitNR
return(limNR)
})
getInterpNormRefl <- function(eventdata, calreflavgs, interpolation){
#Interpolate the radiance and irradiance data for a single event file.
#Then calculate normalized reflectance for the event file.
#Arguments include a single event dataset, the average panel reflectance, and
#the interpolation type (linear, spline, or cubic).
#Return a data frame with four columns: wavelength, irradiance, radiance, and
#normrefl (normal reflectance)
data <- eventdata
calrefl <- calreflavgs
interpolation <- interpolation
allwaves <- seq(303, 1147, by = 1)
#Linear
if(interpolation == "linear"){
InterCalIrr <- approx(x = data$wavelength, y = data$irradiance,
xout = allwaves, method = "linear")
InterCalRad <- approx(x = data$wavelength, y = data$radiance,
xout = allwaves, method = "linear")
InterWhite <- approx(x = data$wavelength, y = calrefl$avg,
xout = allwaves, method = "linear")
}
#Spline
if (interpolation == "spline"){
InterCalIrr <- spline(x = data$wavelength, y = data$irradiance,
xout = allwaves, method = "natural")
InterCalRad <- spline(x = data$wavelength, y = data$radiance,
xout = allwaves, method = "natural")
InterWhite <- spline(x = data$wavelength, y = calrefl$avg,
xout = allwaves, method = "natural")
}
#Cubic Interpolation using the Forsythe, Malcolm and Moler method as described
#in the R help files for the spline() function.
#"...an exact cubic is fitted through the four points at each end of the data,
#and this is used to determine the end conditions"
if (interpolation == "cubic"){
InterCalIrr <- spline(x = data$wavelength, y = data$irradiance,
xout = allwaves, method = "fmm")
InterCalRad <- spline(x = data$wavelength, y = data$radiance,
xout = allwaves, method = "fmm")
InterWhite <- spline(x = data$wavelength, y = calrefl$avg,
xout = allwaves, method = "fmm")
}
interpdata <- data.frame(wavelength = InterCalIrr$x, irradiance = InterCalIrr$y,
radiance = InterCalRad$y, calrefl = InterWhite$y)
#Step 2: Calculate reflectance data by dividing the radiance by the irradiance
#at each wavelength
interpdata$refl <- (interpdata$radiance/interpdata$irradiance)
#Step 3: Calculate the final reflectance by comparing the irradiance signal to
#the mean white panel signal (that is, normalize the data)
interpdata$normrefl <- (interpdata$refl/interpdata$calrefl)
#Step 4: Remove values outside of the possible range of -1 to 1
limitNR <- getLimitNR()
if(limitNR == "nl"){}
if(limitNR == "lim1"){
interpdata$normrefl[which(interpdata$normrefl > 1)] <- 1
interpdata$normrefl[which(interpdata$normrefl < -1)] <- -1
}
if(limitNR == "limNA"){
interpdata$normrefl[which(interpdata$normrefl > 1)] <- NA
interpdata$normrefl[which(interpdata$normrefl < -1)] <- NA
}
return(interpdata)
}
getNumberCalFiles <- reactive({
#Count the number of calibration files entered.
nrow(input$calfiles)
})
getNumberEventFiles <- reactive({
#Count the number of event files entered.
nrow(input$eventfiles)
})
getCalDataList <- reactive({
#For each calibration file entered, use the getDataFromFile function to extract
#the data, then put each data frame into a list. The result is a list of data
#frames, each with three columns: wavelength, radiance, and irradiance
calfiles <- input$calfiles
files <- lapply(X = calfiles[,4], getDataFromFile, input$upchannel)
return(files)
})
getCalDataFrame <- reactive({
#For each calibration file entered, use the getCalDataList function to get a list
#of all the calibration data frames. Then bind them into a single data frame
#with four columns: wavelength, radiance, irradiance, and filename.
files <- getCalDataList()
data <- do.call(rbind, files)
data$filename <- as.factor(rep(input$calfiles[,1], each=256))
return(data)
})
getEventDataList <- reactive({
#For each event file entered, use the getDataFromFile function to extract
#the data, then put each data frame into a list. The result is a list of data
#frames, each with three columns: wavelength, radiance, and irradiance
eventfiles <- input$eventfiles
files <- lapply(X = eventfiles[,4], getDataFromFile, input$upchannel)
for(i in 1:length(files)){files[[i]]$filename <- eventfiles[i,1]}
if(input$direction == "backward"){files <- rev(files)}
return(files)
})
getEventDataFrame <- reactive({
#For each event file entered, use the getEventDataList function to get a list
#of all the event data frames. Then bind them into a single data frame
#with four columns: wavelength, radiance, irradiance, and filename.
files <- getEventDataList()
data <- do.call(rbind, files)
data$filename <- as.factor(rep(input$eventfiles[,1], each=256))
return(data)
})
getAvgCalRefl <- reactive({
#getAvgCalRefl: calculate the average reflectance for all of the white panel
#files, and return a data frame with three columns: wavelength, avg, sd
caldata <- getCalDataList()
paneldata <- data.frame(wavelength = caldata[[1]]$wavelength)
#For each of the white panel files, read in the file, calculate reflectance, and
#add a column to the results file
for(i in 1:length(caldata)){
pfile <- caldata[[i]]
paneldata[,i+1] <- pfile$radiance/pfile$irradiance
}
#Calculate mean reflectance and the standard deviation of the reflectance at every
#wavelength measured in the raw data files
if(length(caldata) == 1){
paneldata$avg <- paneldata[,2]
paneldata$sd <- rep(NA, nrow(paneldata))
} else {
paneldata$avg <- rowMeans(paneldata[,2:ncol(paneldata)])
paneldata$avg[which(paneldata$avg > 1000)] <- NA
paneldata$sd <- apply(paneldata[2:(ncol(paneldata)-1)],1,sd,na.rm=TRUE)
}
avgrefldata <- data.frame(paneldata$wavelength, paneldata$avg, paneldata$sd)
names(avgrefldata) <-c("wavelength","avg","sd")
return(avgrefldata)
})
getEventNormRefl <- reactive({
#getEventNormRefl: for a set of event files, calculate the normalized reflectance
#for each file, using the average reflectance of the white panels. Return a
#data frame with three columns: location, wavelength, and normrefl (normal reflectance).
calrefl <- getAvgCalRefl()
eventdata <- getEventDataList()
interpdata <- lapply(eventdata, getInterpNormRefl, calrefl, input$interpolation)
normrefl <- do.call(rbind, interpdata)
normrefl$location <- rep(1:length(eventdata),each = 845)
normrefl <- normrefl[,c("location","wavelength","normrefl")]
return(normrefl)
})
getEventNormReflWIrrRad <- reactive({
#getEventNormRefl: for a set of event files, calculate the normalized reflectance
#for each file, using the average reflectance of the white panels. Return a
#data frame with five columns: location, wavelength, and normrefl (normal reflectance).
calrefl <- getAvgCalRefl()
eventdata <- getEventDataList()
interpdata <- lapply(eventdata, getInterpNormRefl, calrefl, input$interpolation)
normrefl <- do.call(rbind, interpdata)
normrefl$location <- rep(1:length(eventdata),each = 845)
normrefl <- normrefl[,c("location","wavelength","irradiance","radiance","calrefl",
"refl","normrefl")]
return(normrefl)
})
getEventAvgNormRefl <- reactive({
#Take the data frame with all normalized reflectance values for all events (using
#getEventNormRefl()), calculate a mean normal reflectance for each wavelength,
#and return a data frame with two columns: avgnormrefl and wavelength.
data <- getEventNormRefl()
newdata <- data.frame(tapply(X = data$normrefl, INDEX = list(data$wavelength),
mean, na.rm = TRUE))
names(newdata) <- c("avgnormrefl")
newdata$wavelength <- as.numeric(row.names(newdata))
return(newdata)
})
getIndex <- function(indexdf, indexno){
#Given a data frame of indices and a row number, calculate the specified index
data <- getEventNormRefl()
p1 <- data$normrefl[which(data$wavelength == indexdf$w1[indexno])]
p2 <- data$normrefl[which(data$wavelength == indexdf$w2[indexno])]
p3 <- data$normrefl[which(data$wavelength == indexdf$w3[indexno])]
p4 <- data$normrefl[which(data$wavelength == indexdf$w4[indexno])]
index <- eval(parse(text = indexdf$expression_form[indexno]))
location <- unique(data$location)
indexdata <- data.frame(location, index)
return(indexdata)
}
getIndices <- reactive({
#Calculate all indices in the index list and bind into a single data frame
indexdata <- merge(getIndex(indexlist, 1), getIndex(indexlist, 2), by = "location")
indexdata$date <- rep(getDate(), nrow(indexdata))
indexdata$event <- rep(input$eventno, nrow(indexdata))
indexdata <- indexdata[,c(1,4,5,2,3)]
for(i in 3:nrow(indexlist)){
indexdata <- merge(indexdata, getIndex(indexlist,i), by = "location")
}
names(indexdata) <- c("location","date","event_no",indexlist[,2])
for(i in 4:ncol(indexdata)){
indexdata[,i] <- round(as.numeric(as.character(indexdata[,i])),5)
}
return(indexdata)
})
summarizeIndices <- reactive({
#Calculate the minimum, mean, and maximum values of all of the indices
indices <- getIndices()
mins <- as.data.frame(apply(X = indices[,4:ncol(indices)], MARGIN = 2, FUN = min, na.rm = TRUE))
means <- as.data.frame(apply(X = indices[,4:ncol(indices)], MARGIN = 2, FUN = mean, na.rm = TRUE))
maxs <- as.data.frame(apply(X = indices[,4:ncol(indices)], MARGIN = 2, FUN = max, na.rm = TRUE))
sds <- as.data.frame(apply(X = indices[,4:ncol(indices)], MARGIN = 2, FUN = sd, na.rm = TRUE))
results <- cbind(mins, means, maxs, sds)
names(results) <- c("minimum","mean","maximum","standard_deviation")
results.2 <- data.frame(row.names(results), results)
names(results.2)[1] <- "index"
return(results.2)
})
projectMetadata <- reactive({
df <- data.frame(variable = c(
"Sampling path",
"Unispec serial number",
"Software and version",
"Upward facing fiber optic channel",
"Integration time (ms)",
"Number of files per integration",
"Event number for the day",
"Person who collected data (1)",
"Person who collected data (2)",
"Person who analyzed data",
"Sky condition by class",
"Wind",
"Date data analyzed",
"First timestamp for calibration files",
"First timestamp for event files",
"Calibration file names",
"Event file names",
"Number of calibration files",
"Number of event files",
"Direction of event along transect",
"Wavelength interpolation method",
"Track condition notes",
"Instrumentation notes",
"Weather notes",
"Data file or collection notes"))
df$value <- c(
input$samplingpath,
input$unispec,
getSoftwareVersion(),
input$upchannel,
getIntegrationTime(),
getNumberScans(),
input$eventno,
input$eventperson1,
input$eventperson2,
input$analysisperson,
input$skyclasscondition,
input$skycondition,
input$wind,
input$sunanglestart,
input$sunangleend,
format(Sys.time(), "%Y-%m-%d %H:%M:%S"),
format(getCalTimestamp(), "%Y-%m-%d %H:%M:%S"),
format(getEventTimestamp(), "%Y-%m-%d %H:%M:%S"),
paste(input$calfiles[,1], collapse = ", "),
paste(input$eventfiles[,1], collapse = ", "),
length(input$calfiles[,1]),
length(input$eventfiles[,1]),
input$direction,
input$interpolation,
input$tracknotes,
input$instrumentnotes,
input$weathernotes,
input$datanotes)
return(df)
})
plotCalIrradiance <- reactive({
#Plot all of the irradiance for a given set of panel files
data <- getCalDataFrame()
p <- ggplot(data, aes(x = wavelength, y = irradiance, colour = filename)) +
geom_line()+
geom_point() +
scale_x_continuous(limits = input$cal_waverange,
breaks = c(seq(400,1100,100))) +
scale_y_continuous(limits=c(0, 70000)) +
ylab("Irradiance") +
theme(legend.position="none",
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotCalRadiance <- reactive({
#Plot all of the radiance for a given set of panel files
data <- getCalDataFrame()
p <- ggplot(data, aes(x = wavelength, y = radiance, colour = filename)) +
geom_line()+
geom_point() +
scale_x_continuous(limits = input$cal_waverange,
breaks = c(seq(400,1100,100))) +
scale_y_continuous(limits=c(0, 70000)) +
ylab("Radiance") +
theme(legend.position="none",
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotCalIrrRadSingle <- reactive({
#Plot the irradiance and radiance for any given (using a slider) panel file.
files <- getCalDataList()
p <- ggplot(files[[input$calfileslider]], aes(x = wavelength)) +
geom_line(aes(y = irradiance, color = 'irradiance'))+
geom_line(aes(y = radiance, color = 'radiance')) +
geom_point(aes(y = irradiance, color = 'irradiance')) +
geom_point(aes(y = radiance, color = 'radiance')) +
scale_x_continuous(limits = input$cal_waverange,
breaks = c(seq(400,1100,100))) +
scale_y_continuous(limits=c(0, 70000)) +
ylab("") +
scale_colour_brewer(type = "qual", palette = 6, name = "") +
theme(legend.position = "top",
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotEventIrradiance <- reactive({
#Plot all of the irradiance for a given set of panel files
data <- getEventDataFrame()
p <- ggplot(data, aes(x = wavelength, y = irradiance, colour = filename)) +
geom_line()+
geom_point() +
scale_x_continuous(limits = input$event_waverange,
breaks = c(seq(400,1100,100))) +
scale_y_continuous(limits=c(0, 30000)) +
ylab("Irradiance") +
theme(legend.position="none",
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotEventRadiance <- reactive({
#Plot all of the radiance for a given set of panel files
data <- getEventDataFrame()
p <- ggplot(data, aes(x = wavelength, y = radiance, colour = filename)) +
geom_line()+
geom_point() +
scale_x_continuous(limits = input$event_waverange,
breaks = c(seq(400,1100,100))) +
scale_y_continuous(limits=c(0, 30000)) +
ylab("Radiance") +
theme(legend.position="none",
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotEventIrrRadSingle <- reactive({
#Plot the irradiance and radiance for any given (using a slider) panel file.
files <- getEventDataList()
p <- ggplot(files[[input$eventfileslider]], aes(x = wavelength)) +
geom_line(aes(y = irradiance, color = 'irradiance'))+
geom_line(aes(y = radiance, color = 'radiance')) +
geom_point(aes(y = irradiance, color = 'irradiance')) +
geom_point(aes(y = radiance, color = 'radiance')) +
scale_x_continuous(limits = input$event_waverange,
breaks = c(seq(400,1100,100))) +
scale_y_continuous(limits=c(0, 30000)) +
ylab("") +
scale_colour_brewer(type = "qual", palette = 6, name = "") +
theme(legend.position = "top",
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotAvgCalRefl <- reactive({
#Plot the average reflectance for the calibration panel
calrefl <- getAvgCalRefl()
p <- ggplot(calrefl, aes(x = wavelength, y = avg)) +
geom_line(colour = 'darkblue') +
geom_point(colour = 'darkblue') +
scale_x_continuous(breaks = c(seq(400,1100,100))) +
scale_y_continuous(limits=c(0, 4)) +
ylab("Avg Panel Reflectance") +
theme(legend.position = "top",
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotAvgNormRefl <- reactive({
#Plot average normalized reflectance for the event files
p <- ggplot(getEventAvgNormRefl(), aes(x = wavelength, y = avgnormrefl)) +
geom_line(colour = 'darkblue') +
geom_point(colour = 'darkblue') +
geom_smooth() +
scale_x_continuous(breaks = c(seq(400,1100,100))) +
scale_y_continuous(limits=c(0, 2)) +
ylab("Avg. Normalized Reflectance") +
theme(legend.position = "top",
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotReflHeatMap <- reactive({
#Plot a color map of the normalized reflectance for any given event file
#(using the same slider)
data <- getEventNormRefl()
limitNR <- getLimitNR()
if(limitNR == "nl"){lim <- 2}else{lim <- 1}
p <- ggplot(data, aes(x = location, y = wavelength, fill = normrefl)) +
geom_raster() +
scale_y_continuous(limits = c(400,1000)) +
scale_fill_continuous(name="Normalized\nReflectance", limits = c(0,lim)) +
theme(legend.key.height = unit(1, "cm"),
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotIndexByLocation <- reactive({
data <- getIndices()
data <- melt(data, id.vars = c("location","date","event_no"))
data <- data[data$variable %in% input$indexnames,]
p <- ggplot(data, aes(x = location, y = value, group = variable, colour = variable)) +
geom_point() +
geom_line(size = 0.5) +
geom_smooth(method = input$smoothtype,
formula = y ~ x, size = 1.5) +
scale_x_continuous(breaks = c(seq(0,110,10))) +
ylab("Index value") +
theme(axis.text = element_text(size=12),
axis.title = element_text(size = 14),
legend.position = "top",
legend.key.height = unit(1, "cm"),
legend.text = element_text(size = 12),
legend.title = element_text(size = 12),
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
plotIndexComparison <- reactive({
aes_mapping <- aes_string(x = input$xindex, y = input$yindex)
data <- getIndices()
p <- ggplot(data, mapping = aes_mapping) +
geom_point() +
geom_smooth(method = "lm", formula = y ~ x) +
theme(axis.text = element_text(size=12),
axis.title = element_text(size = 14),
panel.grid.major.y = element_line(size = .5, colour = "gray80"),
panel.grid.major.x = element_line(size = .5, colour = "gray80"),
panel.background = element_rect(fill = "white"))
p
})
#### Output simple timestamp and tables ####
output$caltimestamp <- renderText({
#output a timestamp taken from the first white panel calibration file uploaded.
timestamp <- as.character(getCalTimestamp())
print(timestamp)
})
output$eventtimestamp <- renderText({
#output a timestamp taken from the first white panel calibration file uploaded.
timestamp <- as.character(getEventTimestamp())
timestamp
})
#### Metadata Table ####
output$metadata <- renderDataTable({
metadata <- projectMetadata()
metadata
}, options = list(bSortClasses = TRUE))
#### Index List Table ####
output$indexListTable <- renderDataTable(
indexlist[,c(1,2,7,9)],
options = list(orderClasses = TRUE,
iDisplayLength = 10,
#columnDefs = list(list(width = c("15%","15%", "15%", "55%"))),
class="display compact",
pagingType = "full_numbers"))
#### Locations Table ####
output$locations <- renderDataTable({
locations <- read.csv(input$location_info[1,4], header = TRUE, stringsAsFactors = FALSE)
locations
},
options = list(bSortClasses = TRUE))
#### All Calculated Indices Table ####
output$allIndexTable <- renderDataTable({
indices <- getIndices()
indices <- indices[,c(1,4:ncol(indices))]
indices
},
options = list(bSortClasses = TRUE, sScrollX = "100%",
bScrollCollapse = "true"))
#### Summary Index Table ####
output$summaryIndexTable <- renderDataTable({
indices <- summarizeIndices()
# write.csv(indices, "tables/indices-calculated-summary.csv",
# row.names = FALSE, append = FALSE)
indices
}, options = list(bSortClasses = TRUE))
#### Download Button content ####
output$downloadMetadata <- downloadHandler(
filename = function() {paste('metadata-',getDate(), '-event', input$eventno, '.csv', sep = '')},
content = function(con) {write.csv(projectMetadata(), con, row.names = FALSE)}
)
output$downloadCalIrradiancePlot <- downloadHandler(
filename = function() {paste('plot_cal-irradiance_',getDate(), '-event',
input$eventno, ".png", sep = '')},
content = function(file) {
png(file, width = 6.5, height = 2.5, units = "in", res = 300)
print(plotCalIrradiance())
dev.off()
})
output$downloadCalRadiancePlot <- downloadHandler(
filename = function() {paste('plot_cal-radiance_',getDate(), '-event',
input$eventno, ".png", sep = '')},
content = function(file) {
png(file, width = 6.5, height = 2.5, units = "in", res = 300)
print(plotCalRadiance())
dev.off()
})
output$downloadCalSingleIrrRadPlot <- downloadHandler(
filename = function() {paste('plot_cal-irr-rad_',getDate(), '-event',
input$eventno, '-file', input$calfileslider, ".png",
sep = '')},
content = function(file) {
png(file, width = 6.5, height = 2.5, units = "in", res = 300)
print(plotCalIrrRadSingle())
dev.off()
})
output$downloadEventIrradiancePlot <- downloadHandler(
filename = function() {paste('plot_event-irradiance_',getDate(), '-event',
input$eventno, ".png", sep = '')},
content = function(file) {
png(file, width = 6.5, height = 2.5, units = "in", res = 300)
print(plotEventIrradiance())
dev.off()
})
output$downloadEventRadiancePlot <- downloadHandler(
filename = function() {paste('plot_event-radiance_',getDate(), '-event',
input$eventno, ".png", sep = '')},
content = function(file) {
png(file, width = 6.5, height = 2.5, units = "in", res = 300)
print(plotEventRadiance())
dev.off()
})
output$downloadEventSingleIrrRadPlot <- downloadHandler(
filename = function() {paste('plot_event-irr-rad_',getDate(), '-event',
input$eventno, '-file', input$calfileslider, ".png",
sep = '')},
content = function(file) {
png(file, width = 6.5, height = 2.5, units = "in", res = 300)
print(plotEventIrrRadSingle())
dev.off()
})
output$downloadAvgCalReflPlot <- downloadHandler(
filename = function() {paste('plot_avg-cal-refl_',getDate(), '-event',
input$eventno, ".png",
sep = '')},
content = function(file) {
png(file, width = 6.5, height = 2.5, units = "in", res = 300)
print(plotAvgCalRefl())
dev.off()
})
output$downloadAvgNormReflPlot <- downloadHandler(
filename = function() {paste('plot_avg-norm-refl_',getDate(), '-event',
input$eventno, ".png",
sep = '')},
content = function(file) {
png(file, width = 6.5, height = 2.5, units = "in", res = 300)
print(plotAvgNormRefl())
dev.off()
})
output$downloadReflHeatMap <- downloadHandler(
filename = function() {paste('plot_refl-heatmap_',getDate(), '-event',
input$eventno, ".png",
sep = '')},
content = function(file) {
png(file, width = 6.5, height = 3, units = "in", res = 300)
print(plotReflHeatMap())
dev.off()
})
output$downloadIndexByLocationPlot <- downloadHandler(
# indexnames <- input$indexnames,
# newname <- indexnames[1],
# if(length(indexnames > 1)){
# for(i in 2:length(indexnames)){
# newname <- paste(newname, indexnames[i], sep = "-")
# }},
filename = function() {paste('plot_index-by-location_', getDate(), '-event',
input$eventno, ".png",
sep = '')},
content = function(file) {
png(file, width = 6.5, height = 4, units = "in", res = 300)
print(plotIndexByLocation())
dev.off()
})
output$downloadIndexCompPlot <- downloadHandler(
filename = function() {paste('plot_index-comp-plot_',getDate(), '-event',
input$eventno, ".png",
sep = '')},
content = function(file) {
png(file, width = 6.5, height = 3, units = "in", res = 300)
print(plotIndexComparison())
dev.off()
})
output$downloadEventData <- downloadHandler(
filename = function() {paste('eventdata-', getDate(), '-event', input$eventno, '.csv', sep = '')},
content = function(con) {write.csv(getEventNormReflWIrrRad(), con, row.names = FALSE)}
)
output$downloadIndexData <- downloadHandler(
filename = function() {paste('indexdata-', getDate(), '-event', input$eventno, '.csv', sep = '')},
content = function(con) {write.csv(getIndices(), con, row.names = FALSE)}
)
output$downloadIndexSummaries <- downloadHandler(
filename = function() {paste('indexdata-summary-', getDate(), '-event', input$eventno,'.csv', sep = '')},
content = function(con) {write.csv(summarizeIndices(), con, row.names = FALSE)}
)
output$downloadPdfReport <- downloadHandler(filename = "rHyperSpec_pdf_report.pdf",
content = function(file){
# generate PDF
knit2pdf("rHyperSpec_pdf_report.Rnw")
# copy pdf to 'file'
file.copy("rHyperSpec_pdf_report.pdf", file)
# delete generated files
file.remove("rHyperSpec_pdf_report.pdf",
"rHyperSpec_pdf_report.tex",
"rHyperSpec_pdf_report.aux",
"rHyperSpec_pdf_report.log")
},
contentType = "application/pdf"
)
#### Sliders ####
output$eventFileSlider <- renderUI({
#output a slider bar for the panel files, to be used with 'raweventplot'
n <- nrow(as.data.frame(input$eventfiles))
sliderInput('eventfileslider', "View irradiance and radiance by file",
min = 1, max = n , value = 1, step = 1)
})
output$eventWaveSlider <- renderUI({
#output a slider bar to select the wavelength range to be used in plotting -
#allows a user to zoom in.
sliderInput('event_waverange',label = 'Wavelength range for analysis',
min = 305, max = 1145, value = c(400,1000), step = 10)})
#### Plots ####
output$calFileSlider <- renderUI({
#output a slider bar for the panel files, to be used with 'rawcalplot'
n <- nrow(as.data.frame(input$calfiles))
sliderInput('calfileslider', "View irradiance and radiance by file",
min = 1, max = n , value = 1, step = 1)})
output$calWaveSlider <- renderUI({
#output a slider bar to select the wavelength range to be used in plotting -
#allows a user to zoom in.
sliderInput('cal_waverange',label = 'Wavelength range for analysis',
min = 305, max = 1145, value = c(400,1000), step = 10)})
output$rawcalirrplots <- renderPlot({
print(plotCalIrradiance())
})
output$rawcalradplots <- renderPlot({
print(plotCalRadiance())
})
output$rawcalplot <- renderPlot({
print(plotCalIrrRadSingle())
})
output$raweventirrplots <- renderPlot({
print(plotEventIrradiance())
})
output$raweventradplots <- renderPlot({
print(plotEventRadiance())
})
output$raweventplot <- renderPlot({
print(plotEventIrrRadSingle())
})
output$avgcalreflplot <- renderPlot({
print(plotAvgCalRefl())
})
output$avgnormreflplot <- renderPlot({
print(plotAvgNormRefl())
})
output$reflheatmap <- renderPlot({
print(plotReflHeatMap())
})
output$indexbylocationplot <- renderPlot({
print(plotIndexByLocation())
})
output$indexcompplot <- renderPlot({
print(plotIndexComparison())
})
})