forked from handr003/NEON-capstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Holly.Rmd
84 lines (66 loc) · 1.98 KB
/
Holly.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
---
title: "Holly_NEONcapstone"
author: "Holly Andrews"
date: "June 23, 2016"
output: html_document
---
#Correlating NDVI to temperature in Harvard Forest using NEON and Landsat data
First, I will import Harvard NDVI data and tower IR temperature data from NEON. I will import thermal IR rasters from Landsat for Harvard Forest.
##Load libraries and data
```{r load-libraries}
library(raster)
library(ggplot2)
```
```{r import-data}
lidar <- raster("../NEONdata/NEONdata/D01-Massachusetts/HARV/2014/lidar/HARV_lidarCHM.tif")
tower <- read.csv("../NEONdata/HARV_temp/HARV_temp_30min.csv")
thermal <- raster("../NEONdata/NEONdata/D01-Massachusetts/HARV/2014/HARV_thermal.TIF")
lidar[lidar==0] <- NA
x11()
hist(lidar)
x11()
hist(thermal)
plot(thermal)
```
##Check extents
```{r check-extents}
extent(thermal)
extent(lidar)
```
##Clip to smaller extent
```{r clip-extents}
same_extent <- function(raster1,raster2) {
if (extent(raster1)==extent(raster2)) {
print("Rasters have same extent")
} else {
overlap <- raster::intersect(extent(raster1),extent(raster2))
raster1 <- crop(raster1,overlap)
raster2 <- crop(raster2,overlap)
print("Extents are different, cropping data")
}
raster.stack <- stack(raster1,raster2)
return(raster.stack)
}
if(extent(lidar)==extent(thermal)) {
} else{
print("Extents are different, cropping data")
overlap <- intersect(extent(thermal),extent(lidar))
#now let's crop the lidar data to HSI
thermal <- crop(thermal,overlap)
lidar <- crop(lidar,overlap)
}
thermal <- setExtent(thermal, lidar_aggregated, keepres=FALSE, snap=FALSE)
lidar_aggregated <- setExtent(lidar_aggregated,thermal,keepres=FALSE, snap=FALSE)#check that these should both be FALSE
stack <- brick(lidar_aggregated,thermal)
#check extents again
extent(thermal)
extent(lidar)
extent(lidar_aggregated)
#aggregate rasters
lidar_aggregated <- aggregate(lidar,29.59375)
```
##Plot CHM-thermal regression
```{r plot-regression}
plot(lidar_aggregated,thermal)
lm()
```