-
Notifications
You must be signed in to change notification settings - Fork 1
/
carabids_03_EDA_LAI.R
209 lines (183 loc) · 10.9 KB
/
carabids_03_EDA_LAI.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
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
# Here, we explore the NEON LAI product at the Niwot Ridge site and summarize LAI at the trap-level.
# resources:
# https://www.earthdatascience.org/courses/earth-analytics/remote-sensing-uncertainty/extract-data-from-raster/
# https://www.neonscience.org/dc-plot-raster-data-r
# https://www.earthdatascience.org/courses/earth-analytics/remote-sensing-uncertainty/extract-data-from-raster/
library(dplyr)
library(raster)
library(rgdal)
library(rgeos)
library(ggplot2)
# Load data ---------------------------------------------------------------
LAI_raster_2017 = raster("data_derived/neonLAI_1x1_2017.grd")
LAI_raster_2018 = raster("data_derived/neonLAI_1x1_2018.grd")
LAI_raster_2019 = raster("data_derived/neonLAI_1x1_2019.grd")
load("data_derived/car_coords.RData")
LAI_proj = projection(LAI_raster_2019) #the same across years
trap_spdf <- SpatialPointsDataFrame(coords = car_coords %>%
dplyr::select(trap.Easting, trap.Northing),
data=car_coords %>%
dplyr::select(trap.Easting, trap.Northing),
proj4string = CRS(LAI_proj))
plot_spdf <- SpatialPointsDataFrame(coords = car_coords %>%
dplyr::select(plot.Easting, plot.Northing),
data=car_coords %>%
dplyr::select(plot.Easting, plot.Northing),
proj4string = CRS(LAI_proj))
# Crop LAI raster ---------------------------------------------------------
buff <- 500 #set arbitrary buffer - I think this is in m per the earthdatascience resource
car_extent <- extent(min(car_coords$trap.Easting) - buff, #xmin
max(car_coords$trap.Easting) + buff, #xmax
min(car_coords$trap.Northing) - buff, #ymin
max(car_coords$trap.Northing) + buff) #ymax
LAI_2017_crop <- crop(LAI_raster_2017, car_extent)
LAI_2018_crop <- crop(LAI_raster_2018, car_extent)
LAI_2019_crop <- crop(LAI_raster_2019, car_extent)
# AIS need to save these to data_derived
plot(LAI_2017_crop, main="2017 LAI")
points(car_coords$trap.Easting,car_coords$trap.Northing, pch=20, cex=0.5)
plot(LAI_2018_crop, main="2018 LAI")
plot(LAI_2019_crop, main="2019 LAI")
# What's the difference in LAI between years? -----------------------------
#save a lower resolution raster for plotting
LAI_agg_2017 <- LAI_2017_crop %>% aggregate(fact = 10) #make it 25x25m
LAI_agg_2018 <- LAI_2018_crop %>% aggregate(fact = 10)
LAI_agg_2019 <- LAI_2019_crop %>% aggregate(fact = 10)
hist(LAI_agg_2017, main="2017 LAI")
hist(LAI_agg_2018, main="2018 LAI")
hist(LAI_agg_2019, main="2019 LAI")
# 2018 and 2019 don't look right
plot(LAI_2017_crop, main="2017 LAI",
breaks=c(0,.5,1,1.5,2,2.5,3),
col=terrain.colors(3))
plot(LAI_2018_crop, main="2018 LAI",
breaks=c(0,.5,1,1.5,2,2.5,3),
col=terrain.colors(3))
plot(LAI_2019_crop, main="2019 LAI",
breaks=c(0,.5,1,1.5,2,2.5,3),
col=terrain.colors(3))
# AIS add plot coords too and label so we can visualize the names of the plots
# AIS contacted NEON to ask about the difference in LAI values between years
# Create LAI value around traps -------------------------------------------
# Plots are 40m x 40m. Traps lay within the plot at the middle of each edge. If they laid exactly on plot edge, they would be about 28m from the traps on the neighboring sides. How large should we summarize LAI for each trap? As to not overlap with neighboring traps' buffers, the buffer should be at most 14m. Max, min, avg LAI? for now choose avg
#AIS experiment with different buffer sizes.
# Mean ummarized to trap-level
trap_LAI_avg_2017 <- raster::extract(x = LAI_2017_crop, #raster
y = trap_spdf,
buffer = 10, # specify a 10 m radius
fun = mean, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
trap_LAI_avg_2018 <- raster::extract(x = LAI_2018_crop, #raster
y = trap_spdf,
buffer = 10, # specify a 10 m radius
fun = mean, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
trap_LAI_avg_2019 <- raster::extract(x = LAI_2019_crop, #raster
y = trap_spdf,
buffer = 10, # specify a 10 m radius
fun = mean, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
# Max summarized to trap-level
trap_LAI_max_2017 <- raster::extract(x = LAI_2017_crop, #raster
y = trap_spdf,
buffer = 10, # specify a 10 m radius
fun = max, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
trap_LAI_max_2018 <- raster::extract(x = LAI_2018_crop, #raster
y = trap_spdf,
buffer = 10, # specify a 10 m radius
fun = max, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
trap_LAI_max_2019 <- raster::extract(x = LAI_2019_crop, #raster
y = trap_spdf,
buffer = 10, # specify a 10 m radius
fun = max, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
# Stand dev summarized to trap-level
trap_LAI_sd_2017 <- raster::extract(x = LAI_2017_crop, #raster
y = trap_spdf,
buffer = 10, # specify a 10 m radius
fun = sd, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
trap_LAI_sd_2018 <- raster::extract(x = LAI_2018_crop, #raster
y = trap_spdf,
buffer = 10, # specify a 10 m radius
fun = sd, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
trap_LAI_sd_2019 <- raster::extract(x = LAI_2019_crop, #raster
y = trap_spdf,
buffer = 10, # specify a 10 m radius
fun = sd, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
# Mean summarized to plot-level
plot_LAI_avg_2017 <- raster::extract(x = LAI_2017_crop, #raster
y = plot_spdf,
buffer = 30, # specify a 10 m radius
fun = mean, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
plot_LAI_avg_2018 <- raster::extract(x = LAI_2018_crop, #raster
y = plot_spdf,
buffer = 30, # specify a 10 m radius
fun = mean, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
plot_LAI_avg_2019 <- raster::extract(x = LAI_2019_crop, #raster
y = plot_spdf,
buffer = 30, # specify a 10 m radius
fun = mean, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
# AIS something seems wonky with 2019 LAI, values are too low
# Max summarized to plot-level
plot_LAI_max_2017 <- raster::extract(x = LAI_2017_crop, #raster
y = plot_spdf,
buffer = 30, # specify a 10 m radius
fun = max, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
plot_LAI_max_2018 <- raster::extract(x = LAI_2018_crop, #raster
y = plot_spdf,
buffer = 30, # specify a 10 m radius
fun = max, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
plot_LAI_max_2019 <- raster::extract(x = LAI_2019_crop, #raster
y = plot_spdf,
buffer = 30, # specify a 10 m radius
fun = max, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
# Max summarized to plot-level
plot_LAI_sd_2017 <- raster::extract(x = LAI_2017_crop, #raster
y = plot_spdf,
buffer = 30, # specify a 10 m radius
fun = sd, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
plot_LAI_sd_2018 <- raster::extract(x = LAI_2018_crop, #raster
y = plot_spdf,
buffer = 30, # specify a 10 m radius
fun = sd, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
plot_LAI_sd_2019 <- raster::extract(x = LAI_2019_crop, #raster
y = plot_spdf,
buffer = 30, # specify a 10 m radius
fun = sd, # extract the MEAN value from each trap
sp = TRUE, # create spatial object
stringsAsFactors = FALSE)
# AIS while figuring out what's up with 2019...
# Just take the 2017 average values for trap and plot
plot_trap_LAI_2017
# Save LAI at trap-level to incorporate
save(plot_trap_LAI_2017, file="data_derived/plot_trap_LAI_2017.Rdata")