Remember to download and put into data subdirectory:

Load the following into browser window:

Set-up R Console:

library(raster)
library(rgdal)
library(ggplot2)

raster structure, import, and plotting

dsm_harv <- raster("data/NEON-airborne/HARV_dsmCrop.tif")
dsm_harv_df = as.data.frame(dsm_harv, xy = TRUE)
head(dsm_harv_df)
ggplot() +
  geom_raster(data = dsm_harv_df, 
              aes(x = x, y = y, fill = HARV_dsmCrop)) +
  coord_quickmap()

ggplot() +
  geom_histogram(data = dsm_harv_df, 
                 aes(x = HARV_dsmCrop))

raster math

Show > * Canopy Height Model picture

dtm_harv <- raster("data/NEON-airborne/HARV_dtmCrop.tif")
chm_harv <- dsm_harv - dtm_harv

Do Tasks 1-2 of Canopy Height from Space.

Import and reproject shapefiles

plots_harv <- readOGR("data/NEON-airborne/plot_locations", 
                      "HARV_plots")
chm_harv_df = as.data.frame(chm_harv, xy = TRUE)
plots_harv_df = as.data.frame(plots_harv)
ggplot() +
  geom_raster(data = chm_harv_df, 
              aes(x = x, y = y, fill = layer)) +
  geom_point(data = plots_harv_df, 
             aes(x = coords.x1, y = coords.x2), color = "yellow")
crs(chm_harv)
crs(plots_harv)
plots_harv_utm <- spTransform(plots_harv, crs(chm_harv))
plots_harv_utm_df = as.data.frame(plots_harv_utm)
ggplot() +
  geom_raster(data = chm_harv_df, 
              aes(x = x, y = y, fill = layer)) +
  geom_point(data = plots_harv_utm_df, 
             aes(x = coords.x1, y = coords.x2), color = "yellow")

Extract raster data

plots_chm <- extract(chm_harv, plots_harv_utm)
plots_harv_utm$plot_id
plots_chm <- data.frame(plot_num = plots_harv_utm$plot_id, plot_value = plots_chm)
plots_chm$plot_buffer_value <- extract(chm_harv, plots_harv_utm, buffer = 10, fun = mean)

Do Tasks 3-4 of Canopy Height from Space.

Stacks of rasters

ndvi_files = list.files("data/HARV_NDVI/",
                         full.names = TRUE,
                         pattern = "HARV_NDVI.*.tif")
ndvi_rasters <- stack(ndvi_files)
plot(ndvi_rasters)
plots_harv <- readOGR("data/NEON-airborne/plot_locations", "HARV_plots")
plots_harv_utm <- spTransform(plots_harv, crs(ndvi_rasters))
plots_harv_ndvi <- extract(ndvi_rasters, plots_harv)
as.data.frame(t(plots(harv_ndvi)))
avg_ndvi <- cellStats(ndvi_rasters, mean)
samp_period <- 1:length(avg_ndvi)
avg_ndvi_df <- data.frame(samp_period, avg_ndvi)
ggplot(avg_ndvi_df, aes(x = samp_period, y = avg_ndvi)) +
  geom_point()

Do Phenology from Space.

Making your own point data

points_csv <- read.csv("data/NEON-airborne/plot_locations/HARV_PlotLocations.csv")
points_crs <- crs("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
points_spat <- SpatialPointsDataFrame(
	points_csv[c('long', 'lat')], 
	points_csv, 
	proj4string = points_crs)
str(points_spat)
points_spat_utm <- spTransform(points_spat, crs(ndvi_rasters))
extract(ndvi_rasters, points_spat_utm, buffer = 10, fun = mean)

Map of point data

map = map_data("state", region = "massachusetts")
ggplot() +
  geom_polygon(data = map, 
               aes(x = long, y = lat, group = group), 
               fill = "grey")
points_spat_df <- as.data.frame(points_spat)
ggplot() +
  geom_polygon(data = map, 
               aes(x = long, y = lat, group = group), 
               fill = "grey") +
  geom_point(data = points_spat_df, 
             aes(x = long, y = lat))
usmap = map_data("usa")
ggplot() +
  geom_polygon(data = usmap, 
               aes(x = long, y = lat, group = group), 
               fill = "grey")

Do Species Occurrences Map.