-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproject_merge.Rmd
131 lines (116 loc) · 3.22 KB
/
project_merge.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
---
title: "Merge Habitat Restoration Projects with BMP-Treatment Type Projects"
author: "Ed Sherwood"
date: "July 19, 2017"
output: html_document
---
```{r message = F, warning = F, results = 'hide'}
library(tidyverse)
library(readxl)
library(ggmap)
library(lubridate)
library(geosphere)
library(stringi)
library(tibble)
knitr::knit('project_merge.Rmd', tangle = TRUE)
file.copy('project_merge.R', 'R/project_merge.R', overwrite = T)
file.remove('project_merge.R')
```
```{r warning = F, message = F, fig.width = 8, fig.height = 6}
fl <- 'data-raw/TBEP_Restoration Database_11_21_07_JRH.csv'
# clean up habitat restoration data
habdat <- fl %>%
read_csv %>%
select(Latitude, Longitude, Project_Completion_Date, `Project_Technology`, `Project_Activity`, `Acres-1`) %>%
rename(
lat = Latitude,
lon = Longitude,
date = Project_Completion_Date,
tech = `Project_Technology`,
type = `Project_Activity`,
acre = `Acres-1`
) %>%
mutate(
id = stringi::stri_rand_strings(nrow(.), length = 4),
lat = as.numeric(lat),
lon = as.numeric(lon),
date = as.numeric(date),
tech = toupper(tech),
type = toupper(type)
) %>%
filter(lat > 27.3 & lat < 28.2) %>%
filter(!is.na(date))
# habitat restoration station locs
habstat <- habdat %>%
select(id, lat, lon) %>%
unique
# normalized habitat data
habdat <- habdat %>%
select(-lat, -lon)
save(habdat, file = 'data/habdat.RData', compress = 'xz')
save(habstat, file = 'data/habstat.RData', compress = 'xz')
```
Habitat restoration projects:
```{r}
head(habdat)
```
```{r warning = F, message = F, fig.width = 8, fig.height = 6}
bmp_tr <- 'data-raw/apdb_completed_categorized.csv'
# clean up BMP-Treatment data
bmpdat <- bmp_tr %>%
read_csv %>%
select(Unique_Project_ID, ProjectLatitude, ProjectLongitude, Completion_Date, Project_Technology, Project_Activity, Acres) %>%
rename(
id = Unique_Project_ID,
lat = ProjectLatitude,
lon = ProjectLongitude,
date = Completion_Date,
tech = Project_Technology,
type = Project_Activity,
acre = Acres
) %>%
mutate(
id = stri_rand_strings(nrow(.), length = 4),
lat = as.numeric(lat),
lon = as.numeric(lon),
date = as.numeric(date),
tech = toupper(tech),
type = toupper(type)
) %>%
filter(lat > 27.3 & lat < 28.2) %>%
filter(!is.na(date))
# BMP-Treatment station locs
bmpstat <- bmpdat %>%
select(id, lat, lon) %>%
unique
# normalized habitat data
bmpdat <- bmpdat %>%
select(-lat, -lon)
save(bmpdat, file = 'data/bmpdat.RData', compress = 'xz')
save(bmpstat, file = 'data/bmpstat.RData', compress = 'xz')
```
BMP-Treatment projects:
```{r}
head(bmpdat)
```
Locations of BMP Treatment projects:
```{r}
head(bmpstat)
```
Combine cleaned up datasets
```{r}
restdat <- rbind(habdat, bmpdat)
reststat <- rbind(habstat, bmpstat)
save(restdat, file = 'data/restdat.RData', compress = 'xz')
save(reststat, file = 'data/reststat.RData', compress = 'xz')
checkdata <- restdat %>%
select(type) %>%
unique()
checkdata2 <- restdat %>%
select(tech) %>%
unique()
checkdata3 <- restdat %>%
select(type, tech) %>%
unique()
write.csv(checkdata3, file = 'data/proj_classes.csv')
```