-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExploratoryAnalysis_committee.Rmd
2111 lines (1739 loc) · 73.9 KB
/
ExploratoryAnalysis_committee.Rmd
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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "ExploratoryAnalysis_Committee"
author: "Zach"
date: "5/27/2021"
output: html_document
editor_options:
chunk_output_type: console
---
This file will explore ideas proposed by the committee during the prospectus defense on 5/25/2021
Import Libraries to be used
```{r}
library(lubridate)
library(tidyverse)
library(ggplot2)
library(patchwork)
library(tidycensus)
library(dplyr)
library(readr)
library(sf)
library(tmap)
library(rgeos)
library(RColorBrewer)
library(rgdal)
library(XML)
library(units)
```
### Checking Value of Q
It is expected that with time KBDI plots will become equal regardless of the initial value of Q
Copy and paste KBDI code
## Import the summary of the day data and add columns to the data frame
Assign no rainfall on days with missing values.
For Tallahassee Station TLH
```{r}
TLH.df <- read_csv(file = 'Data/TLH_Daily1940.csv') %>%
rename(Date = DATE) %>%
mutate(Year = year(Date),
month = month(Date, label = TRUE, abbr = TRUE),
doy = yday(Date),
MaxTemp = TMAX,
MinTemp = TMIN,
Rainfall24 = PRCP,
Rainfall24 = replace_na(Rainfall24, 0),
Rainfall24mm = Rainfall24 * 25.4)
#Fill in the missing temperature data
TLH.df$MaxTemp[TLH.df$Date == "2005-07-08"] <- 96
```
Calculating qlm using inital Q-value of 269. Add these columns to the TLH.df data frame. This data frame will be referenced and filtered as needed.
```{r}
Rainfall24 <- TLH.df$Rainfall24
PR <- dplyr::lag(Rainfall24)
PR[1] <- 0
CumR <- 0
NetR <- numeric()
for(i in 1:length(Rainfall24)) {
R24 <- Rainfall24[i]
if (R24 == 0) {
NetR[i] <- 0
CumR <- 0
}
else if(R24 > 0 & R24 <= .2) {
CumR <- CumR + R24
if (PR[i] > .2 | CumR > .2) NetR[i] <- R24
else if (CumR > .2) NetR[i] <- CumR - .2
else NetR[i] <- 0
}
else if (R24 > .2) {
if (CumR <= .2) {
NetR[i] <- CumR + R24 - .2
CumR <- CumR + R24
}
else {
NetR[i] <- R24
CumR <- CumR + R24
}
}
}
TLH.df$NetR <- NetR
Q <- 269
R <- 59.23 # average annual rainfall for TLH in inches
MaxTemp <- TLH.df$MaxTemp
Ql <- numeric()
DeltaQl <- numeric()
for(i in 1:length(Rainfall24)){
DeltaQ <- (800 - Q) * (.968 * exp(.0486 * MaxTemp[i]) - 8.3) /(1 + 10.88 * exp(-.0441 * R)) * .001
Q <- ifelse(NetR[i] == 0, Q + DeltaQ, (Q + DeltaQ) - NetR[i] * 100)
Q <- ifelse(Q < 0, 0, Q)
Ql <- c(Ql, Q)
DeltaQl <- c(DeltaQl, DeltaQ)
}
TLH.df$Ql <- Ql
TLH.df$Qlm <- Ql * .254 # tenth of an inch to mm
TLH.df$DeltaQl <- DeltaQl
TLH.df$DroughtIndex <- floor(Ql/100)
```
A new data frame is created to compare initial Q values. Q is representative of the starting value of KBDI. Here a column of several Q values is created to be used and compared among multiple plots. Daily KBDI is calculated for each initial Q value. This is testing the theory that with enough time elapsed, the initial value of Q does not matter.
rangeQ.df data frame is initialized at start of TLH.df data frame. (March 1940)
```{r}
Rainfall24 <- TLH.df$Rainfall24
PR <- dplyr::lag(Rainfall24)
PR[1] <- 0
CumR <- 0
NetR <- numeric()
for(i in 1:length(Rainfall24)) {
R24 <- Rainfall24[i]
if (R24 == 0) {
NetR[i] <- 0
CumR <- 0
}
else if(R24 > 0 & R24 <= .2) {
CumR <- CumR + R24
if (PR[i] > .2 | CumR > .2) NetR[i] <- R24
else if (CumR > .2) NetR[i] <- CumR - .2
else NetR[i] <- 0
}
else if (R24 > .2) {
if (CumR <= .2) {
NetR[i] <- CumR + R24 - .2
CumR <- CumR + R24
}
else {
NetR[i] <- R24
CumR <- CumR + R24
}
}
}
TLH.df$NetR <- NetR
R <- 59.23
rangeQ.df <- TLH.df %>%
select(Date, Rainfall24, MaxTemp, NetR)
for(i in 1:9){
Q2 <- i-1
Q <- Q2*100
MaxTemp <- TLH.df$MaxTemp
Ql <- numeric()
for(i in 1:length(Rainfall24)){
DeltaQ <- (800 - Q) * (.968 * exp(.0486 * MaxTemp[i]) - 8.3) /(1 + 10.88 * exp(-.0441 * R)) * .001
Q <- ifelse(NetR[i] == 0, Q + DeltaQ, (Q + DeltaQ) - NetR[i] * 100)
Q <- ifelse(Q < 0, 0, Q)
Ql <- c(Ql, Q)
}
rangeQ.df[, ncol(rangeQ.df)+1] <- Ql
colnames(rangeQ.df) <- c("Date", "Rainfall24", "MaxTemp", "NetR", "Q0", "Q100", "Q200", "Q300", "Q400", "Q500", "Q600", "Q700", "Q800")
}
```
```{r}
head(rangeQ.df)
```
Plot Q values for first year of data period (1940)
```{r}
p1_1940 <- rangeQ.df %>%
filter(year(Date) == 1940) %>%
ggplot(mapping = aes(x = Date)) +
geom_line(aes(y = Q0, color = "0")) +
geom_line(aes(y = Q400, color = "400")) +
geom_line(aes(y = Q800, color = "800")) +
scale_color_manual("Initial Q-values",
breaks = c("0", "400", "800"),
values = c("red", "blue", "black")) +
ylab("KBDI") +
scale_x_date(date_labels = "%b %Y")
#theme(legend.position = "bottom")
#theme(legend.position = c(0.8,0.3)
p2_1940 <- rangeQ.df %>%
filter(year(Date) == 1940) %>%
ggplot(mapping = aes(x = Date)) +
geom_line(mapping = aes(y = Rainfall24)) +
ylab("24Hr Net Rainfall") +
scale_x_date(date_labels = "%b %Y")
p2_1940 / p1_1940 +
plot_annotation(
title = "KBDI values merge with time regardless of initial Q-values",
subtitle = "Q-values intialized at 0, 400, and 800",
caption = "Period of Record: March 1940 - December 1940") +
theme(legend.position = "bottom")
```
Filtering TLH data frame to start in 1991. This is one year prior to the fire data obtained from the Forest Service Research Data Archive
```{r}
TLH1991.df <- TLH.df %>%
filter(year(Date) >= 1991)
```
Initialize different Q values starting in 1991 and create rangeQ1991.df
```{r}
Rainfall24 <- TLH1991.df$Rainfall24
PR <- dplyr::lag(Rainfall24)
PR[1] <- 0
CumR <- 0
NetR <- numeric()
for(i in 1:length(Rainfall24)) {
R24 <- Rainfall24[i]
if (R24 == 0) {
NetR[i] <- 0
CumR <- 0
}
else if(R24 > 0 & R24 <= .2) {
CumR <- CumR + R24
if (PR[i] > .2 | CumR > .2) NetR[i] <- R24
else if (CumR > .2) NetR[i] <- CumR - .2
else NetR[i] <- 0
}
else if (R24 > .2) {
if (CumR <= .2) {
NetR[i] <- CumR + R24 - .2
CumR <- CumR + R24
}
else {
NetR[i] <- R24
CumR <- CumR + R24
}
}
}
TLH1991.df$NetR <- NetR
R <- 59.23
rangeQ1991.df <- TLH1991.df %>%
select(Date, Rainfall24, MaxTemp, NetR)
for(i in 1:9){
Q2 <- i-1
Q <- Q2*100
MaxTemp <- TLH1991.df$MaxTemp
Ql <- numeric()
for(i in 1:length(Rainfall24)){
DeltaQ <- (800 - Q) * (.968 * exp(.0486 * MaxTemp[i]) - 8.3) /(1 + 10.88 * exp(-.0441 * R)) * .001
Q <- ifelse(NetR[i] == 0, Q + DeltaQ, (Q + DeltaQ) - NetR[i] * 100)
Q <- ifelse(Q < 0, 0, Q)
Ql <- c(Ql, Q)
}
rangeQ1991.df[, ncol(rangeQ1991.df)+1] <- Ql
colnames(rangeQ1991.df) <- c("Date", "Rainfall24", "MaxTemp", "NetR", "Q0", "Q100", "Q200", "Q300", "Q400", "Q500", "Q600", "Q700", "Q800")
}
```
Plot 1991, year before fire data starts
```{r}
p1_1991 <- rangeQ1991.df %>%
filter(year(Date) == 1991) %>%
ggplot(mapping = aes(x = Date)) +
geom_line(aes(y = Q0, color = "0")) +
geom_line(aes(y = Q400, color = "400")) +
geom_line(aes(y = Q800, color = "800")) +
scale_color_manual("Initial Q-values",
breaks = c("0", "400", "800"),
values = c("red", "blue", "black")) +
ylab("KBDI") +
scale_x_date(date_labels = "%b %Y")
#theme(legend.position = "bottom")
#theme(legend.position = c(0.8,0.3)
p2_1991 <- rangeQ1991.df %>%
filter(year(Date) == 1991) %>%
ggplot(mapping = aes(x = Date)) +
geom_line(mapping = aes(y = Rainfall24)) +
ylab("24Hr Net Rainfall") +
scale_x_date(date_labels = "%b %Y")
p2_1991 / p1_1991 +
plot_annotation(
title = "KBDI values merge with time regardless of initial Q-values",
subtitle = "Q-values intialized at 0, 400, and 800",
caption = "Period of Record: 1991") +
theme(legend.position = "bottom")
```
focus plot on first month
```{r}
p1_1991 <- rangeQ1991.df %>%
filter(year(Date) == 1991) %>%
filter(month(Date) == 1) %>%
ggplot(mapping = aes(x = Date)) +
geom_line(aes(y = Q0, color = "0")) +
geom_line(aes(y = Q400, color = "400")) +
geom_line(aes(y = Q800, color = "800")) +
scale_color_manual("Initial Q-values",
breaks = c("0", "400", "800"),
values = c("red", "blue", "black")) +
ylab("KBDI")
#theme(legend.position = "bottom")
#theme(legend.position = c(0.8,0.3)
p2_1991 <- rangeQ1991.df %>%
filter(year(Date) == 1991) %>%
filter(month(Date) == 1) %>%
ggplot(mapping = aes(x = Date)) +
geom_line(mapping = aes(y = Rainfall24)) +
ylab("24Hr Net Rainfall")
p2_1991 / p1_1991 +
plot_annotation(
title = "KBDI values merge with time regardless of initial Q-values",
subtitle = "Q-values intialized at 0, 400, and 800",
caption = "Period of Record: January 1991") +
theme(legend.position = "bottom")
```
Display Q-values for 1941, the first full year of data. Compare this to 1991, one year before the period of fire data.
Filtering TLH data frame to start in 1991. This is one year prior to the fire data obtained from the Forest Service Research Data Archive
```{r}
TLH1941.df <- TLH.df %>%
filter(year(Date) >= 1941)
```
Initialize different Q values starting in 1941 and create rangeQ1941.df
```{r}
Rainfall24 <- TLH1941.df$Rainfall24
PR <- dplyr::lag(Rainfall24)
PR[1] <- 0
CumR <- 0
NetR <- numeric()
for(i in 1:length(Rainfall24)) {
R24 <- Rainfall24[i]
if (R24 == 0) {
NetR[i] <- 0
CumR <- 0
}
else if(R24 > 0 & R24 <= .2) {
CumR <- CumR + R24
if (PR[i] > .2 | CumR > .2) NetR[i] <- R24
else if (CumR > .2) NetR[i] <- CumR - .2
else NetR[i] <- 0
}
else if (R24 > .2) {
if (CumR <= .2) {
NetR[i] <- CumR + R24 - .2
CumR <- CumR + R24
}
else {
NetR[i] <- R24
CumR <- CumR + R24
}
}
}
TLH1941.df$NetR <- NetR
R <- 59.23
rangeQ1941.df <- TLH1941.df %>%
select(Date, Rainfall24, MaxTemp, NetR)
for(i in 1:9){
Q2 <- i-1
Q <- Q2*100
MaxTemp <- TLH1941.df$MaxTemp
Ql <- numeric()
for(i in 1:length(Rainfall24)){
DeltaQ <- (800 - Q) * (.968 * exp(.0486 * MaxTemp[i]) - 8.3) /(1 + 10.88 * exp(-.0441 * R)) * .001
Q <- ifelse(NetR[i] == 0, Q + DeltaQ, (Q + DeltaQ) - NetR[i] * 100)
Q <- ifelse(Q < 0, 0, Q)
Ql <- c(Ql, Q)
}
rangeQ1941.df[, ncol(rangeQ1941.df)+1] <- Ql
colnames(rangeQ1941.df) <- c("Date", "Rainfall24", "MaxTemp", "NetR", "Q0", "Q100", "Q200", "Q300", "Q400", "Q500", "Q600", "Q700", "Q800")
}
```
Create plots of 1941 to be compared with 1991
```{r}
p1_1941 <- rangeQ1941.df %>%
filter(year(Date) == 1941) %>%
ggplot(mapping = aes(x = Date)) +
geom_line(aes(y = Q0, color = "0")) +
geom_line(aes(y = Q400, color = "400")) +
geom_line(aes(y = Q800, color = "800")) +
scale_color_manual("Initial Q-values",
breaks = c("0", "400", "800"),
values = c("red", "blue", "black")) +
ylab("KBDI") +
scale_x_date(date_labels = "%b %Y")
#theme(legend.position = "bottom")
#theme(legend.position = c(0.8,0.3)
p2_1941 <- rangeQ1941.df %>%
filter(year(Date) == 1941) %>%
ggplot(mapping = aes(x = Date)) +
geom_line(mapping = aes(y = Rainfall24)) +
ylab("24Hr Net Rainfall") +
scale_x_date(date_labels = "%b %Y")
```
Create 4 panel plot showing showing 1941 (first full year of KBDI data) and 1991(one year prior to the start of fire data) side by side.
```{r}
((p2_1941 + ylim(0,5)) + (p2_1991 + ylim(0, 5))) /
((p1_1941 + theme(legend.position = "none")) + p1_1991) +
plot_annotation(
title = "KBDI values merge with time regardless of initial Q-values",
subtitle = "Q-values intialized at 0, 400, and 800",
caption = "Period of Record: 1940 (Left) & 1991 (Right)")
```
##Explore lightning data and concerns mentioned by committee.
Get lightning data
Daily county-level counts 1986-2013. Data location: https://www1.ncdc.noaa.gov/pub/data/swdi/reports/county/byFips/
Note: this data is not spatial and cannot be bounded by the ANF.For exploratory analysis purposes, this data will be explored across counties that the ANF is within. These counties are Liberty, Wakulla, Franklin, and Leon.
First get the Florida fips codes for Liberty, Wakulla, Franklin and Leon counties, then get the data.
```{r}
FLfips <- fips_codes %>%
filter(state == "FL") %>%
filter(county %in% c("Liberty County", "Wakulla County", "Franklin County", "Leon County")) %>%
pull(county_code)
fn <- paste0("https://www1.ncdc.noaa.gov/pub/data/swdi/reports/county/byFips/swdireport-12", FLfips, "-BETA.csv")
lightningdata.df <- data.frame()
for(i in 1:length(fn)){
X <- read.csv(fn[i], na.strings = "NULL", header = TRUE, stringsAsFactors = FALSE)
lightningdata.df <- rbind(lightningdata.df, X)
}
lightningdata.df <- lightningdata.df %>%
mutate(SEQDAY = as.Date(SEQDAY),
DAY = day(SEQDAY),
MONTH = month(SEQDAY),
YEAR = year(SEQDAY))
```
Attempt to read files from each downloaded csv because website import is not reliable and does not always open
```{r}
lightningdata1.df <- list.files(path = "C:/Users/zlaw9/OneDrive/GITHUB/KDBI code/FIPS_LightningData",
pattern = "*.csv", full.names = TRUE) %>%
lapply(read_csv) %>%
bind_rows
lightningdata1.df <- lightningdata1.df %>%
mutate(SEQDAY = as.Date(SEQDAY),
DAY = day(SEQDAY),
MONTH = month(SEQDAY),
YEAR = year(SEQDAY)) %>%
#missing data beyond 5/20/2013 for FIPS #12037. Remove last 5 rows from data set. This addresses the parsing failure and removes data that is NA.
filter(SEQDAY <= "2013-05-20")
```
lightningdata1.df gives lighting data for each individual county based on fips code. Combine total lightning strikes in ANF counties by date.
```{r}
countlightning.df <- lightningdata1.df %>%
group_by(SEQDAY) %>%
summarise(LightningCount = sum(FCOUNT_NLDN))
```
Explore the relationship between high lightning count days and number of lightning sparked wildfires in the ANF
County boundaries will be used instead of forest boundaries to keep bounds of fires and lightning consistent. Run county bounds code chunk.
Import Forest Boundaries to explore lightning fire data bounded by the ANF
```{r}
if(!"S_USA.NFSLandUnit" %in% list.files()){
download.file("https://data.fs.usda.gov/geodata/edw/edw_resources/shp/S_USA.NFSLandUnit.zip",
"S_USA.NFSLandUnit.zip")
unzip("S_USA.NFSLandUnit.zip")
}
NF_Bounds.sf <- st_read(dsn = "s_USA.NFSLandUnit.shp") %>%
st_transform(crs = 3086)
anfbounds.sf <- NF_Bounds.sf %>%
filter(NFSLANDU_2 == "Apalachicola National Forest")
#when running code from ANF_Fires Run this line
#ANF_Boundary.sf <- NF_Bounds.sf %>%
#filter(NFSLANDU_2 == "Apalachicola National Forest")
```
Import County Boundaries of the forest. This will make the bounds consistent across both the fire data set and the lightning data set.
```{r}
ANFcountyBounds.sf <- st_read(dsn = "ANFCounties.shp") %>%
st_transform(crs = 3086)
```
Import fire data
This is the old data set containing fires only until 2015
```{r}
if(!"FL_Fires" %in% list.files()){
download.file("http://myweb.fsu.edu/jelsner/temp/data/FL_Fires.zip",
"FL_Fires.zip")
unzip("FL_Fires.zip")
}
FL_Fires.sf <- st_read(dsn = "FL_Fires") %>%
st_transform(crs = 3086)
#filtered fires within ANF bounds
#anf_fires.sf <- st_join(FL_Fires.sf, anfbounds.sf, join = st_within) %>%
#filter(NFSLANDU_2 == 'Apalachicola National Forest')
#filtered for county bounds of ANF. This is to match the bounds of the lightning dataset
anf_fires.sf <- st_join(FL_Fires.sf, ANFcountyBounds.sf, join = st_within) %>%
filter(CNTY_FIPS != "NA") %>%
select(FOD_I, FIRE_N, FIRE_Y, DISCOVERY_, STAT_CAU_1, FIRE_SIZE, FIRE_SIZE_, LATIT, LONGI, NAME, FIPS, geometry)
anf_LF.sf <- anf_fires.sf %>%
filter(STAT_CAU_1 == "Lightning")
```
Archived fire data has been updated through 2018.
Website link with data and metadata
https://www.fs.usda.gov/rds/archive/Catalog/RDS-2013-0009.5
Attempt to read file in directly from website. Receiving warning messages:
1: In CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
GDAL Message 1: This version of GeoPackage user_version=0x0000283C (10300, v1.3.0) on 'C:\Users\zlaw9\OneDrive\GITHUB\KDBI code\Data\updatedFireData\Data\FPA_FOD_20210617.gpkg' may only be partially supported
2: attribute variables are assumed to be spatially constant throughout all geometries
Taking a long time to load.
```{r}
#if(!"Fires2018" %in% list.files()){
#download.file("https://www.fs.usda.gov/rds/archive/products/RDS-2013-0009.5/RDS-2013-0009.5_GPKG.zip",
#"Data/updatedFireData/Fires2018.zip")
#unzip("Data/updatedFireData/Fires2018.zip",
#exdir = "Data/updatedFireData")
#}
updatedFires.sf <- st_read(dsn = "Data/updatedFireData/Data/FPA_FOD_20210617.gpkg", layer = "Fires") %>%
filter(STATE == "FL") %>%
st_transform(crs = st_crs(ANFcountyBounds.sf)) %>%
st_intersection(ANFcountyBounds.sf) %>%
select(FOD_ID, FIRE_NAME, FIRE_YEAR, DISCOVERY_DATE, NWCG_CAUSE_CLASSIFICATION, NWCG_GENERAL_CAUSE, FIRE_SIZE, FIRE_SIZE_CLASS, LATITUDE, LONGITUDE, NAME, FIPS_CODE, Shape)
anf_LF.sf <- updatedFires.sf %>%
filter(NWCG_GENERAL_CAUSE == "Natural")
```
Reformat date column to not include time. Rename to match other merged columns
```{r}
anf_LF.sf$DISCOVERY_DATE <- as.Date(anf_LF.sf$DISCOVERY_DATE)
anf_LF.sf <- anf_LF.sf %>%
rename(DISCOVERY_ = DISCOVERY_DATE)
```
Fire set downloaded and pulled from file rather than directly from the website. Importing from GPKG runs slow. Downloaded and converted to more user friendly shapefiles in ESRI.
New Data Set has change categories for cause. Lightning is not listed. Is lightning the equivalent of fires filtered as natural? Explore this at the bottom of the rmd.
```{r}
updatedFires.sf <- st_read(dsn = "C:/Users/zlaw9/OneDrive/GITHUB/KDBI code/updatedFires",
layer = "FLFiresUpdated") %>%
st_transform(crs = st_crs(ANFcountyBounds.sf)) %>%
st_intersection(ANFcountyBounds.sf) %>%
select(FOD_ID, FIRE_NAME, FIRE_YEAR, DISCOVERY_, NWCG_CAUSE, NWCG_GENER, FIRE_SIZE, FIRE_SIZE_, LATITUDE, LONGITUDE, NAME, FIPS, geometry)
anf_LF.sf <- updatedFires.sf %>%
filter(NWCG_CAUSE == "Natural")
```
View fire points that have been bounded by four counties (Liberty, Leon, Wakulla, and Franklin)
```{r}
tmap_mode("view")
tm_shape(ANFcountyBounds.sf) +
tm_borders()
tm_shape(anf_LF.sf) +
tm_dots(col = "orange")
```
create data set containing fires and lightning counts. Match the years across the data sets (1992 - 2013)
Merge1.df is a new data frame that contains the number of lightning strikes and fires occurring in the Apalachicola National Forest broken down by day from 1992 - 2013.
```{r}
#exploreLF <- anf_LF.sf %>%
#filter(FIRE_Y <= 2013)
countfires.df <- anf_LF.sf %>%
#countfires.df <- exploreLF %>%
count(DISCOVERY_) %>%
rename(FireCount = n, Date = DISCOVERY_)
countlightning.df <- countlightning.df %>%
filter(year(SEQDAY) >= 1992)
#rename(LightningCount = FCOUNT_NLDN)
merge1.df <- left_join(x = countlightning.df, y = countfires.df, by = c("SEQDAY" = "Date")) %>%
rename(Date = SEQDAY) %>%
select(Date, LightningCount, FireCount)
```
Create new data frame (TLH1.df) to match the dates with merge1.df. These data frames will be combined.
```{r}
TLH1.df <- TLH.df %>%
filter(year(Date) >= 1992) %>%
filter(Date <= "2013-05-25")
```
Merge data frames to have lightning strike count, fire count and Qlm all in one dataframe
```{r}
merge2.df <- left_join(x = merge1.df, y = TLH1.df, by = c("Date")) %>%
select(Date, LightningCount, FireCount, Ql)
merge2.df$FireBool <- !is.na(merge2.df$FireCount)
```
General linear regression - Study how lightning influences the probability of fire occurrence
Predict the occurrence of a fire for each day in the data set based on lightning count.
Note: This plot includes days with zero lightning strikes and concludes that on days with zero lightning strikes there is a 3% chance of a lightning ignited wildfire occurring. A lightning fire cannot occur without lighting. Should be zero percent.
```{r}
#general linear regression
glmLightning <- glm(formula = FireBool ~ LightningCount, family = binomial, data = merge2.df)
#probabilities based on glm
pred_glmLightning <- predict(object = glmLightning,
type = "response",
se.fit = TRUE)
#creating confidence interval
lowerLightning <- pred_glmLightning$fit - (1.96*pred_glmLightning$se.fit)
upperLightning <- pred_glmLightning$fit + (1.96*pred_glmLightning$se.fit)
ggplot(mapping = aes(x = merge2.df$LightningCount, y = pred_glmLightning$fit)) +
geom_ribbon(aes(ymin = lowerLightning, ymax = upperLightning), fill = "grey") +
geom_line(color = "blue") +
ylab("Predicited Probablility") +
xlab("Number of Lightning Strikes") +
labs(
title = "Predicted Probability of a Fire Occurrence Based on the Number of Lightning Strikes in a Day",
subtitle = "With a 95% Confidence Interval",
caption = "Period of Record: 1-1-1992 to 5-20-2013")
```
Filter data for only dates in the fire season before running glm.
When filtering to only the fire season, there is more uncertainty, and the model is closer to linear.
```{r}
fireSeasondates2013.df <- merge2.df %>%
filter(month(Date) == 05 | month(Date) == 06 | month(Date) == 07)
#general linear regression
glmLightningFS <- glm(formula = FireBool ~ LightningCount, family = binomial, data = fireSeasondates2013.df)
#probabilities based on glm
pred_glmLightningFS <- predict(object = glmLightningFS,
type = "response",
se.fit = TRUE)
#creating confidence interval
lowerLightningFS <- pred_glmLightningFS$fit - (1.96*pred_glmLightningFS$se.fit)
upperLightningFS <- pred_glmLightningFS$fit + (1.96*pred_glmLightningFS$se.fit)
ggplot(mapping = aes(x = fireSeasondates2013.df$LightningCount, y = pred_glmLightningFS$fit)) +
geom_ribbon(aes(ymin = lowerLightningFS, ymax = upperLightningFS), fill = "grey") +
geom_line(color = "blue") +
ylab("Predicited Probablility") +
xlab("Number of Lightning Strikes") +
labs(
title = "Predicted Probability of Fire Occurrence Based on the Number of Lightning Strikes in a Day\nFiltered By Fire Season Months",
subtitle = "With 95% Confidence Interval",
caption = "Fire Season Months (May - July) 1992 - 2013")
```
General linear regression - Study how KBDI impacts lightning wildfire occurrence.
Update to include fires beyond 2012. No longer bounded by lightning data dates and can use full fire data set.
qlm file data frame needs to match new fire data frame dates. Filter TLH.df which was initialized in 1940. This data frame can be referenced cause Q-values merge and values will be the same as initializing one year prior to the start. This limits the amount of code and time to run the entire qlm code chunk again
```{r}
qlm2018fires <- TLH.df %>%
filter(year(Date) >= 1992) %>%
filter(year(Date) <= 2018)
```
```{r}
countfiresmerge2018.df <- left_join(x = qlm2018fires, y = countfires.df, by = c("Date" = "Date")) %>%
select(Date, FireCount, Ql)
countfiresmerge2018.df$FireBool <- !is.na(countfiresmerge2018.df$FireCount)
```
```{r}
glmQl <- glm(formula = FireBool ~ Ql, family = binomial, data = countfiresmerge2018.df)
pred_glmQl <- predict(object = glmQl,
type = "response",
se.fit = TRUE)
lowerQl <- pred_glmQl$fit - (1.96*pred_glmQl$se.fit)
upperQl <- pred_glmQl$fit + (1.96*pred_glmQl$se.fit)
ggplot(mapping = aes(x = countfiresmerge2018.df$Ql, y = pred_glmQl$fit)) +
geom_ribbon(aes(ymin = lowerQl, ymax = upperQl), fill = "grey") +
geom_line(color = "blue") +
ylab("Predicited Probablility") +
xlab("Daily Ql") +
labs(
title = "Predicted Probability of Fire Occurrence Based on Daily KBDI Values",
subtitle = "With 95% Confidence Interval",
caption = "Period of Record: 1992 to 2018")
```
KBDI impacts on lightning wildfire occurrence during the fire season. KBDI has a much stronger impact during the fire season months.
```{r}
fireSeasondates2018.df <- countfiresmerge2018.df %>%
filter(month(Date) == 05 | month(Date) == 06 | month(Date) == 07)
glmQlFS <- glm(formula = FireBool ~ Ql, family = binomial, data = fireSeasondates2018.df)
pred_glmQlFS <- predict(object = glmQlFS,
type = "response",
se.fit = TRUE)
lowerQlFS <- pred_glmQlFS$fit - (1.96*pred_glmQlFS$se.fit)
upperQlFS <- pred_glmQlFS$fit + (1.96*pred_glmQlFS$se.fit)
ggplot(mapping = aes(x = fireSeasondates2018.df$Ql, y = pred_glmQlFS$fit)) +
geom_ribbon(aes(ymin = lowerQlFS, ymax = upperQlFS), fill = "grey") +
geom_line(color = "blue") +
ylab("Predicited Probablility") +
xlab("Daily Ql") +
labs(
title = "Predicted Probability of Fire Occurrence Based on Daily KBDI Values\nFiltered By Fire Season Months",
subtitle = "With 95% Confidence Interval",
caption = "Fire Season Months (May - July) 1992 - 2018")
```
Run general linear regression. The number of lightning strikes and the saturation of the soil are both statistically significant.
```{r}
GLM <- glm(formula = FireBool ~ LightningCount + Ql, family = binomial, data = merge2.df)
pred_GLM <- predict(object = GLM,
type = "response",
se.fit = TRUE)
ggplot(mapping = aes(x = merge2.df$Ql, y = merge2.df$LightningCount, color = pred_GLM$fit)) +
geom_point() +
scale_color_gradient(low = "orange", high = "red4") +
xlab("KBDI") +
ylab("Number of Lightning Strikes") +
labs(color = "Probability of Fire") +
labs(title = "Predicted Probability of Fire Occurrence\nBased on Daily KBDI Values and Daily Lightning Strikes",
caption = "Period of Record: 1-1-1992 to 5-20-2012")
#GLM
#summary(GLM)
#exp(GLM$coefficients)
```
Filter for fire season
```{r}
GLMFS <- glm(formula = FireBool ~ LightningCount + Ql, family = binomial, data = fireSeasondates2013.df)
pred_GLMFS <- predict(object = GLMFS,
type = "response",
se.fit = TRUE)
ggplot(mapping = aes(x = fireSeasondates2013.df$Ql, y = fireSeasondates2013.df$LightningCount, color = pred_GLMFS$fit)) +
geom_point() +
scale_color_gradient(low = "orange", high = "red4") +
xlab("KBDI") +
ylab("Number of Lightning Strikes") +
labs(color = "Probability of Fire") +
labs(title = "Predicted Probability of Fire Occurrence\nBased on Daily KBDI Values and Daily Lightning Strikes",
caption = "Fire Season Months (May - July) 1992 - 2013")
```
### Does the occurance of a large fire create a time lag in the occurrence of another fire?
make a correction to the anf_LF.sf data frame. This data frame is bounded by counties because counties were used to bound lightning data. Correct this to account for the anf boundaries rather than county boundaries
```{r}
anf_LF_corrected.sf <- anf_LF.sf %>%
st_transform(crs = st_crs(anfbounds.sf)) %>%
st_intersection(anfbounds.sf)
```
```{r}
tmap_mode("view")
tm_shape(anfbounds.sf) +
tm_borders()
tm_shape(anf_LF_corrected.sf) +
tm_dots(col = "orange")
```
Explore relationship between the number of fires and fire size.
```{r}
seasonFires <- anf_LF_corrected.sf %>%
filter(month(DISCOVERY_) == 05 | month(DISCOVERY_) == 06 | month(DISCOVERY_) == 07) %>%
count(FIRE_YEAR) %>%
rename(Year = FIRE_YEAR, nFIRES = n) %>%
st_set_geometry(NULL)
LargestFires <- anf_LF.sf %>%
filter(month(DISCOVERY_) == 05 | month(DISCOVERY_) == 06 | month(DISCOVERY_) == 07) %>%
group_by(FIRE_YEAR) %>%
summarise(LargestFire = max(FIRE_SIZE)) %>%
rename(Year = FIRE_YEAR) %>%
st_set_geometry(NULL)
seasonSummary <- merge(x = seasonFires, y = LargestFires, by = c("Year"))
head(seasonSummary)
#cor(seasonSummary$nFIRES, seasonSummary$LargestFire)
```
###Spatial Distribution of Natural Wildfires
suggested from `suggest_crs()`. Here projected 2779 NAD83(HARN) / Florida North
```{r}
library(spatstat)
library(maptools)
#remotes::install_github("walkerke/crsuggest")
library(crsuggest)
suggest_crs(anfbounds.sf)
W <- anfbounds.sf %>%
st_transform(crs = 2779) %>%
as_Spatial() %>%
as.owin()
#FireSeason Object
SeasonFires.ppp <- anf_LF.sf %>%
filter(month(DISCOVERY_) %in% c(5, 6, 7)) %>%
st_geometry() %>%
st_transform(crs = 2779) %>%
as_Spatial() %>%
as.ppp()
SeasonFires.ppp <- SeasonFires.ppp[W] %>%
rescale(s = 1000,
unitname = "km")
summary(SeasonFires.ppp)
#April Fire Object
AprilFires.ppp <- anf_LF.sf %>%
filter(month(DISCOVERY_) %in% c(4)) %>%
st_geometry() %>%
st_transform(crs = 2779) %>%
as_Spatial() %>%
as.ppp()
AprilFires.ppp <- AprilFires.ppp[W] %>%
rescale(s = 1000,
unitname = "km")
summary(AprilFires.ppp)
#May Fires Object
MayFires.ppp <- anf_LF.sf %>%
filter(month(DISCOVERY_) %in% c(5)) %>%
st_geometry() %>%
st_transform(crs = 2779) %>%
as_Spatial() %>%
as.ppp()
MayFires.ppp <- MayFires.ppp[W] %>%
rescale(s = 1000,
unitname = "km")
summary(MayFires.ppp)
#June Fires Object
JuneFires.ppp <- anf_LF.sf %>%
filter(month(DISCOVERY_) %in% c(6)) %>%
st_geometry() %>%
st_transform(crs = 2779) %>%
as_Spatial() %>%
as.ppp()
JuneFires.ppp <- JuneFires.ppp[W] %>%
rescale(s = 1000,
unitname = "km")
summary(JuneFires.ppp)
#July Fires object
JulyFires.ppp <- anf_LF.sf %>%
filter(month(DISCOVERY_) %in% c(7)) %>%
st_geometry() %>%
st_transform(crs = 2779) %>%
as_Spatial() %>%
as.ppp()
JulyFires.ppp <- JulyFires.ppp[W] %>%
rescale(s = 1000,
unitname = "km")
summary(JulyFires.ppp)
```
Fire Season Distribution
```{r}
par(mfrow=c(1,2))
SeasonFires.ppp %>%
plot(main = "Season Fires")
SeasonFires.ppp %>%
density() %>%
plot(main = "Spatial Distribution - Season Fires")
```
Distribution across April, May, June, July
```{r}
par(mfrow=c(2,2))
AprilFires.ppp %>%
density() %>%
plot(main = "April")
MayFires.ppp %>%
density() %>%
plot(main = "May")
JuneFires.ppp %>%
density() %>%
plot(main = "June")
JulyFires.ppp %>%
density() %>%
plot(main = "July")
```
April Fire Distribution - Only 4 fires across all April months in the data set?
```{r}
par(mfrow=c(2,2))
AprilFires.ppp %>%
plot(main = "April")
MayFires.ppp %>%
plot(main = "May")
JuneFires.ppp %>%
plot(main = "June")
JulyFires.ppp %>%
plot(main = "July")
```
Explore how the distribution of wildfires may vary based on season
```{r}
FallFires.ppp <- anf_LF.sf %>%
filter(month(DISCOVERY_) %in% c(8, 9, 10)) %>%
st_geometry() %>%
st_transform(crs = 2779) %>%
as_Spatial() %>%
as.ppp()
FallFires.ppp <- FallFires.ppp[W] %>%
rescale(s = 1000,
unitname = "km")
summary(FallFires.ppp)
WinterFires.ppp <- anf_LF.sf %>%
filter(month(DISCOVERY_) %in% c(11, 12, 1)) %>%
st_geometry() %>%
st_transform(crs = 2779) %>%
as_Spatial() %>%
as.ppp()
WinterFires.ppp <- WinterFires.ppp[W] %>%
rescale(s = 1000,
unitname = "km")
summary(WinterFires.ppp)
SpringFires.ppp <- anf_LF.sf %>%
filter(month(DISCOVERY_) %in% c(2, 3, 4)) %>%
st_geometry() %>%
st_transform(crs = 2779) %>%
as_Spatial() %>%